[引用] Dump / Restore system via SSH

Amplify’d from www.wonkity.com

dump(8)/restore(8)

dump(8) and restore(8) have been the standard FreeBSD backup
utilities since vaccuum tubes roamed the earth. They work at the
filesystem level, and so only back up used space. restore can
provide access to individual files in a backup, useful when your system
is fine but you just need that one file out of a backup.

dump is not particularly fast, but because it only backs up actual
data (filesystem blocks in use), can be faster than whole-disk backup
methods.

Each filesystem must be dumped individually; this is sometimes expressed
as “dump does not cross filesystems”. On a normal FreeBSD system, a
full backup includes dumps of /, /var, and /usr. /tmp is a
separate filesystem, too, but you’re not supposed to be storing valuable
data there.

/ and /var are usually small and trivial to dump, with /usr being
much larger. If you’re dumping to files on a FAT filesystem, the 2G/4G
file size limit can be an unwelcome surprise.

dump can take either mountpoints like /var, or the device node of an
unmounted filesystem, like /dev/ada0s1d. If a filesystem is mounted,
the -L snapshot option should be used.

Useful dump Options

One of the nice usability features of FreeBSD is that ctrl-T sends a
SIGINFO to the controlling process. With dump, this means you can
press ctrl-T and get a “percent completed” report. That report will
also be printed automatically every five minutes, if you’re the patient
sort.

Giving dump a larger cache with the -C option can help speed things
up. Be a little cautious: since dump forks multiple processes, the
cache size will be used multiple times. If you overcommit memory and
the computer starts to swap, the dump will change from “annoyingly slow”
to “glacially agonizing”. The dump(8) man page recommends 8 to 32
megabytes. It also recommends always using -C when the -L snapshot
option is used.

Directories to be skipped in a dump can be marked with the nodump
flag:

# chflags nodump /usr/ports

Because the Ports Collection is easy to recreate and often contains
large distfiles, it’s a prime candidate to skip in backups. (On
computers with poor net access where those distfiles are hard to
download, you might want to back it up; as always, it depends on your
situation.)

Other large directories with easy-to-recreate or unnecessary data could
include /usr/src and various types of cache, like web browser cache or
the files created by devel/ccache.

restore(8)

restore has many useful options, including the ability to
interactively choose individual files for restoration. Here, we’ll only
show restoring a whole filesystem, but please see the restore(8) man
page.

Caution restore puts restored files in the current directory. Don’t
forget to cd to the right directory before running restore.

Simple dump

Back up a single system to an external hard drive. The external hard
drive is UFS-formatted, so file size limits are not a problem.

# mount /dev/da0s1 /mnt
# dump -C16 -0uanL -h0 -f /mnt/root.dump /
# dump -C16 -0uanL -h0 -f /mnt/var.dump /var
# dump -C16 -0uanL -h0 -f /mnt/usr.dump /usr
# umount /mnt

The external drive is mounted at /mnt, then the /, /var, and
/usr filesystems are dumped to files on it.

Restoring this backup is also pretty simple. This example restores the
/var filesystem into a temporary directory. This is the type of
restore used when you’re looking for some files that were accidentally
deleted. If you were restoring a whole system, you’d restore the data
over the filesystem where it originated.

# mount /dev/da0s1 /mnt
# mkdir /tmp/oldvar
# cd /tmp/oldvar
# restore -ruf /mnt/var.dump
# umount /mnt

See the restore(8) man page for the -i option, which provides a
shell-like interactive session for selecting files and directories to
restore.

dump With Compression

# mount /dev/da0s1 /mnt
# dump -C16 -0uanL -h0 -f - / | gzip -2 > /mnt/root.dump.gz
# dump -C16 -0uanL -h0 -f - /var | gzip -2 > /mnt/var.dump.gz
# dump -C16 -0uanL -h0 -f - /usr | gzip -2 > /mnt/usr.dump.gz
# umount /mnt

Like the previous example, but dump output is piped through gzip,
creating compressed dump files.

gzcat is used to decompress these files for restoration. This example
restores to a temporary directory so the backed-up directories and files
are available but don’t overwrite the current files.

# mount /dev/da0s1 /mnt
# mkdir /tmp/usr
# gzcat /mnt/usr.dump.gz | (cd /tmp/usr && restore -ruf -)
# umount /mnt

dump Via SSH

ssh allows dump to send files to another system on the network,
which is very handy, at least if you have more than one system.

# dump -C16 -0uanL -h0 -f - /    | gzip -2 | ssh -c blowfish user@otherhost dd of=root.dump.gz
# dump -C16 -0uanL -h0 -f - /var | gzip -2 | ssh -c blowfish user@otherhost dd of=var.dump.gz
# dump -C16 -0uanL -h0 -f - /usr | gzip -2 | ssh -c blowfish user@otherhost dd of=usr.dump.gz

otherhost is the system receiving the backup files, and user is the
username on that other system. As before, gzip compresses the files,
but then ssh logs in to the other system and copies the input into a
file in the user’s home directory with dd.

Backup speeds may be slower than to a directly-connected disk. dump
and ssh prompts are mixed together, which can be confusing when ssh
is waiting for a password. But the convenience of this method sometimes
makes a FreeBSD notebook or netbook a better “backup device” than a
simple external hard disk.

Restoring these files is a reversal of the dump command line:

# mkdir /tmp/root /tmp/var /tmp/usr
# ssh -c blowfish usr@otherhost dd if=root.dump.gz | gzcat | (cd /tmp/root && restore -ruf -)
# ssh -c blowfish usr@otherhost dd if=var.dump.gz | gzcat | (cd /tmp/var && restore -ruf -)
# ssh -c blowfish usr@otherhost dd if=usr.dump.gz | gzcat | (cd /tmp/usr && restore -ruf -)

Copying Filesystems

Filesystems can be copied directly from one disk to another by piping
the output of dump right into restore. Source and target
filesystems don’t have to be the same size, the target just needs to be
large enough to hold all the data in the source.

This example copies a running FreeBSD system onto a new drive. Slices
and partitions have already been set up on the new disk, da0. The
target is the first slice, with a traditional FreeBSD partition layout:
a is /, d is /var, e is /tmp, and f is /usr. See
Disk
Setup On FreeBSD
for background.

/var and / are copied last. They are smaller and may have changed
during the copy of the much-larger /usr filesystem.

# mount /dev/da0s1f /mnt
# dump -C16 -0uanL -h0 -f - /usr | (cd /mnt && restore -ruf -)
# umount /mnt
# mount /dev/da0s1e /mnt
# dump -C16 -0uanL -h0 -f - /tmp | (cd /mnt && restore -ruf -)
# umount /mnt
# mount /dev/da0s1d /mnt
# dump -C16 -0uanL -h0 -f - /var | (cd /mnt && restore -ruf -)
# umount /mnt
# mount /dev/da0s1a /mnt
# dump -C16 -0uanL -h0 -f - / | (cd /mnt && restore -ruf -)
# umount /mnt

Read more at www.wonkity.com

 
See this Amp at http://bit.ly/gvtObC

Leave a Reply

你的電子郵件位址並不會被公開。 必要欄位標記為 *