Ok, this is defiantly worth writing... especially for new users
Here i will cover how to backup/restore (to file) FreeBSD using native utilities called dump and restore
note: dump and restore works only for UFS (aka FFS)
Backing up system
To backup system you need to use dump utility
backup:
where /dev/ad0s1d is any of your partitions, slices or disks, formated with UFS
Backup and compress on the fly
-0 - means to backup entire filesystem
-f name - output to file/device, or to stdout if you use -
-a - you need this if you output to file. (tells dump not to worry about the backup media volume)
-u - Means to update dumpdates file
-L - needed if you backup mounted filesystem
Restoring system
to restore system restart in single user mode
format filesystem that you want to restore
in backup example, we backed up /dev/ad0s1d, so let's format it now
now you need to mount it
Let's imagine you backed up files to usb stick (da0, in root directory)
we need to mount it
Important note: you need space in /tmp to be able to restore
if you run out of space in /tmp, mount some filesystem somewhere and
create symbolic links from /tmp to that mount point
now to restore from backup you need to cd to dir where you mounted partition that you want to restore
to restore from uncompressed backup
to restore from compressed backup
And that is it
now you can delete file dumpdates (or something like that, check for weird file in target directory, in our case /mnt/target)
now unmount filesystems and reboot
Some notes
you can do incremental backups - backup everything and then backup only files that have changed since (on current backup level) see manual for more info
you can use dump/restore to clone your system to other PC's
you will probably need to copy Master Boot Record (MBR) as well
to backup MBR:
to restore MBR:
Tips
* I prefer to compress backup, you can guess why
* if you backup /usr you may delete content of ports directory
this will speed up backup process, and reduce size of backup...
It's good thing because by the time you will restore /usr from backups
/usr/ports will be outdated, and you will need to update them anyway.
And portsnap works very well (fast) in fetching ports
* I prefer to do full backups, that way you can be 100% sure, there won't
be any confusing situations
* if you want to do backups while using filesystem, make sure you haven't
deleted .snap directory, on partition that you want to backup
* if you have backed up encrypted drive, you need to somehow encrypt backups
because if someone gets these files, he can restore them to his pc, and read your files at will. (I used this method in FreeBSD + Geli guide, to encrypt drive, but process can be reversed)
Resources
dump(8)
restore(8)
Update 1
Moving system
You can move system from disk to disk on fly with
you can do the same using sudo
Update 2
as OpenBSD suggests, using gzip instead of bzip2 will seed up compression at cost of larger (very little) archives
so now i suggest using gzip to compress and zcat to uncompress on fly
I've tested it, and i was amazed.
No more Bzip2 for me
Update 3
Just wanted to remind, that you don't need to use -u flag if you're using dump from fixit...
Update 4
You can dump UFS filesystem and restore to any other FS. Dump is FS specific, while restore isn't.
Note that you probably can't use linux restore to restore dumpfile created on FreeBSD and wise versa, because dumpfile formats ar probably different
Update 5
To increase compression ratio you can use xz(1) (which I personally prefer lately) instead of gzip(1)
Here i will cover how to backup/restore (to file) FreeBSD using native utilities called dump and restore
note: dump and restore works only for UFS (aka FFS)
Backing up system
To backup system you need to use dump utility
backup:
Code:
$ dump -0Lauf /path/to/backups/ad0s1d.dump /dev/ad0s1d
Backup and compress on the fly
Code:
$ dump -0Lauf - /dev/ad0s1d | bzip2 > /path/to/backups/ad0s1d.dump.bz2
-0 - means to backup entire filesystem
-f name - output to file/device, or to stdout if you use -
-a - you need this if you output to file. (tells dump not to worry about the backup media volume)
-u - Means to update dumpdates file
-L - needed if you backup mounted filesystem
Restoring system
to restore system restart in single user mode
format filesystem that you want to restore
in backup example, we backed up /dev/ad0s1d, so let's format it now
Code:
$ newfs -U /dev/ad0s1d
now you need to mount it
Code:
$ mkdir /mnt/target
$ mount /dev/ad0s1d /mnt/target
we need to mount it
Code:
$ mount -t msdosfs /dev/da0 /mnt/usb
Important note: you need space in /tmp to be able to restore
if you run out of space in /tmp, mount some filesystem somewhere and
create symbolic links from /tmp to that mount point
now to restore from backup you need to cd to dir where you mounted partition that you want to restore
Code:
$ cd /mnt/target
to restore from uncompressed backup
Code:
$ restore -rf /mnt/usb/ad0s1d.dump
to restore from compressed backup
Code:
$ bzcat /mnt/usb/ad0s1d.dump.bz2 | restore -rf -
And that is it
now you can delete file dumpdates (or something like that, check for weird file in target directory, in our case /mnt/target)
now unmount filesystems and reboot
Some notes
you can do incremental backups - backup everything and then backup only files that have changed since (on current backup level) see manual for more info
you can use dump/restore to clone your system to other PC's
you will probably need to copy Master Boot Record (MBR) as well
to backup MBR:
Code:
$ dd if=/dev/ad0 of=/path/to/mbr.img bs=512 count=1
to restore MBR:
Code:
$ dd if=/path/to/mbr.img of=/dev/ad0 bs=512 count=1
Tips
* I prefer to compress backup, you can guess why
* if you backup /usr you may delete content of ports directory
this will speed up backup process, and reduce size of backup...
It's good thing because by the time you will restore /usr from backups
/usr/ports will be outdated, and you will need to update them anyway.
And portsnap works very well (fast) in fetching ports
* I prefer to do full backups, that way you can be 100% sure, there won't
be any confusing situations
* if you want to do backups while using filesystem, make sure you haven't
deleted .snap directory, on partition that you want to backup
* if you have backed up encrypted drive, you need to somehow encrypt backups
because if someone gets these files, he can restore them to his pc, and read your files at will. (I used this method in FreeBSD + Geli guide, to encrypt drive, but process can be reversed)
Resources
dump(8)
restore(8)
Update 1
Moving system
You can move system from disk to disk on fly with
Code:
$ newfs -U /dev/ad2s1a
$ mount /dev/ad2s1a.... /target
$ cd /target
$ dump -0Lauf - /dev/ad1s1a | restore -rf -
you can do the same using sudo
Code:
$ sudo echo
$ sudo dump -0Lauf - /dev/ad1s1a | sudo restore -rf -
Update 2
as OpenBSD suggests, using gzip instead of bzip2 will seed up compression at cost of larger (very little) archives
so now i suggest using gzip to compress and zcat to uncompress on fly
I've tested it, and i was amazed.
No more Bzip2 for me
Update 3
Just wanted to remind, that you don't need to use -u flag if you're using dump from fixit...
Update 4
You can dump UFS filesystem and restore to any other FS. Dump is FS specific, while restore isn't.
Note that you probably can't use linux restore to restore dumpfile created on FreeBSD and wise versa, because dumpfile formats ar probably different
Update 5
To increase compression ratio you can use xz(1) (which I personally prefer lately) instead of gzip(1)