Snapshot in OpenSolaris and system recovery based on zfs

Author: Hai-Ou Jiang
Email:Hai-Ou.Jiang@Sun.COM

In Solaris 10 or other type of Solaris based on ufs file system, you can use the command“ufsdump” or “ufsrestore” to backup or recover the file system(you should uninstall the file system firstly), and use “fssnap” to create an online snapshot of the file system to backup it. Snapshot is an excellent solution of the online file system backup.

What is snapshot? It is a quick shot of the online file system, which store data into a backup file for restoration. The snapshot file is a bit-mapped file, and will occupy the storage until the snapshot is deleted. The size of file will change with the activity of the file system, dependent on the change between last snapshot and now. Once the snapshot is created, you can treat it as other devices. If we try to uninstall an active file system forcedly, the snapshot will be deleted automatically.

In the Solaris based on ufs, the command to create ufs snapshot is:
fssnap –F ufs –o bs=snapshot_path /snapshot_filesystem

In OpenSolaris, because the default file system is zfs, based on the conceipt of storage pool, the operation to create snapshot is different from which in ufs, and below is the instance of zfs snapshot creation:
zfs snapshot rpool/ROOT/opensolaris@basic

After you create a new snapshot for a file system(for example: /export/home), you will find the size of it is 0KB. However, from now on, the operations you do will be recorded in the snapshot, such as create or delete a file. Therefore, the file will become larger and larger. Once the system is rolled back by an existing snapshot, all operations you have done after the creation time of this snapshot will be recovered. An instance of snapshot is followed:

haiou@opensolaris:~$ zfs list
NAME                                 USED  AVAIL  REFER  MOUNTPOINT
rpool                               3.05G  2.86G    57K  /rpool
rpool@install                         17K      -    55K  -
rpool/ROOT                          3.00G  2.86G    18K  /rpool/ROOT
rpool/ROOT@install                    15K      -    18K  -
rpool/ROOT/opensolaris              3.00G  2.86G  2.42G  legacy
rpool/ROOT/opensolaris@install      60.0M      -  2.22G  -
rpool/ROOT/opensolaris/opt           529M  2.86G   529M  /opt
rpool/ROOT/opensolaris/opt@install    72K      -  3.61M  -
rpool/export                        53.2M  2.86G    19K  /export
rpool/export@install                  15K      -    19K  -
rpool/export/home                   53.1M  2.86G  46.2M  /export/home
rpool/export/home@install             18K      -    21K  -
//view the current zfs file system and snapshot
haiou@opensolaris:~$ pfexec zfs snapshot rpool/export/home@a
//create a snapshot for /export/home
haiou@opensolaris:~$ pwd
/export/home/haiou
haiou@opensolaris:~$ ls
Desktop
haiou@opensolaris:~$ touch a //create a file “a” in current directory
haiou@opensolaris:~$ gedit a //edit file “a”
haiou@opensolaris:~$ mkdir b //create a new directory in current directory
haiou@opensolaris:~$ ls
a b Desktop
haiou@opensolaris:~$ pfexec zfs rollback rpool/export/home@a
//roll back the system by using a snapshot
//we can use ‘-r’ after ‘rollback’ to force deletion of the recent snapshots, for example:
// pfexec zfs rollback –r rpool/export/home@a
haiou@opensolaris:~$ ls
Desktop
// There is no file name “a” and no directory name “b” in the current directory, the system has been rolled back successfully
Besides, OpenSolaris may not boot normally because of some invalid operation or update of some system package. Some snapshots are created during the system installation by default, so you can rollback the system to the state of installation. The process is followed:

1. start from CD/ROM with OpenSolaris Live CD
2. switch to the role of“root”, password is “opensolaris”
3. mount the existing opensolaris in the disk, use “zpool import -f rpool”
4. use the existing snapshot to recover
“zfs rollback rpool/ROOT/opensolaris@install”
5. init 6

Now the system is rolled back to the state of installation, and can boot normally. You may find some software installed are not existed. To avoid this, you'd better create some snapshots after you installed OpenOffice, NetBeans, Sun studio or other software, which can be used to recover the system. In a word, snapshot is a very excellent system backup solution.

Reference:
http://www.superhaiou.com/articles/opensolaris%E4%B8%8B%E7%9A%84snapshot%E5%8F%8A%E5%9F%BA%E4%BA%8Ezfs%E7%9A%84%E7%B3%BB%E7%BB%9F%E6%81%A2%E5%A4%8D.html

评论:

发表一条评论:
  • HTML语法: 禁用
About

This is Chinese Functional CA Team Blog. Any suggestion is appreciated.

Search

Archives
« 九月 2015
星期日星期一星期二星期三星期四星期五星期六
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
今天