发新话题
打印

“Request System Snapshot”的解释

“Request System Snapshot”的解释

“Request System Snapshot” Command Explained
By: Dean Pemberton



The “request system snapshot” command executes a PERL snapshot script called /sbin/snapshot. This script takes a backup of the running filesystem and config (the “/” and “/config” partitions) and places it onto alternate media. If you have booted from the compact flash (CF), then snapshot will backup the CF to the hard-drive. If you have booted from the hard-drive then snapshot will backup the hard-drive to the CF.



Here is a quick overview of how the script works and an explanation of why it performs the tasks that it does. If you need a more in-depth explanation of this script, then I have also produced a line-by-line annotation of the actual PERL code. E-mail me for a copy.



The first thing that the script does when it starts up is to have a look at the current version of the /etc/fstab file, so lets do the same:



# version 3

# Device Mountpoint FStype Options Dump Pass#

/dev/wd0s1a / ufs rw 1 1

/dev/wd2s1e /altconfig ufs rw,noauto 2 0

/dev/wd2s1a /altroot ufs rw,noauto 1 0

/dev/wd0s1e /config ufs rw 2 2

/dev/wd2s1f /var ufs rw,noauto 2 0

/dev/wd2s1b none swap sw 0 0

proc /proc procfs rw 0 0

/dev/wd2s1b /tmp mfs rw,noauto 0 0



The ‘/’ and ‘/config’ filesystems are on one physical device (/dev/wd0 in this case) and ‘/altroot’ and ‘/altconfig’ are on the other (/dev/wd2).



‘/altroot’ is the backup device for ‘/’. If ‘/’ is on the flash then ‘/altroot’ will be on the hard-drive and vice-versa. Similarly ‘/altconfig’ is the backup device for ‘/config’.



After checking that the backup filesystems are present, the script creates new filesystems (i.e. runs “newfs” command) on them and then backs up the current filesystems to them (using native FreeBSD “dump” and “restore” commands).



Once the actual backups are complete there is one more important job that the snapshot script has to do. In order to understand why it needs to do this, we need to give an example.



In the current system we can see that we have booted from flash (/dev/wd0) and we are backing up to hard-drive (/dev/wd2). In the backup process we have just taken the fstab file from the flash and backed it up to the hard-drive. This file tells us that we mount ‘/’ from /dev/wd0s1a and ‘/config’ from /dev/wd0s1e. Both of these locations are on the flash disk.



If we now reboot this router and the flash fails, we will start to boot from the hard-drive. The problem with this is that the fstab on the hard-drive is telling us to mount filesystems that are on the flash.



What we need to do is to edit the fstab file on the hard-drive to reference devices that are on the hard-drive.



Here is a copy of the fstab after we have edited it on the hard-drive:



# version 3

# Device Mountpoint FStype Options Dump Pass#

/dev/wd2s1a / ufs rw 1 1

/dev/wd0s1e /altconfig ufs rw,noauto 2 0

/dev/wd0s1a /altroot ufs rw,noauto 1 0

/dev/wd2s1e /config ufs rw 2 2

/dev/wd2s1f /var ufs rw,noauto 2 0

/dev/wd2s1b none swap sw 0 0

proc /proc procfs rw 0 0

/dev/wd2s1b /tmp mfs rw,noauto 0 0



Notice we are now mounting the ‘/’ and ‘/config’ filesystems from the hard-drive (/dev/wd2), and the ‘/altroot’ and ‘/altconfig’ filesystems from the flash (/dev/wd0).



This way, once we have successfully booted from the hard-drive, we can simply perform another snapshot to rebuild the filesystems on the flash.

TOP

整个中文翻译版的出来该有多好,还是谢谢楼主了。

TOP

发新话题