PC-BSD Backup-Howto

* This is still under construction. Having gotton very tired before getting*
* this far. Makes this less then optimal. Also since I have little in the *
* way of practical exp. It will probably show. I've never had need or using*
* any of my backups. *
* *
* I did enjoy learning a few new things like basic cpio usage, well. *
* I've read about using tar/cpio/afio/dump before. But I've only really *
* used bsdtar with / without gzip/bzip2 for the most part. *
* I will get stuff cleaned up as soon as I can. Feedback/comments always *
* Welcome. *
* *
* Chow *

The most important policy a computer owner ever works on. Is his/her backup
plan, what happens if that hard drive blows up or you erase all your mp3s ?

Since PC-BSD is a desktop based OS, I’ll think more so from a desktop users
perspective then a server. I also don’t know of many people that have ‘tape’
drives at home so I’m not saying any thing about what I don’t own.

Why should I back up my data ?

0.) In case of hard ware failure, namely the hard drive

1.) In case of disaster. Such as fire/flood/electric surge

2.) In case of accidental deletion, oops I just shredded my tax returns the
night before tax day !

3.) In case you have to reinstall the Operating System and want your data.

4.) Just in case you install another Operating System and it over writes some

All good reasons to have a plan, further more its generally assumed that before
you go installing OSes, partitioning drives, e.t.c. that you got back ups.

Ok, so I need backups but where to put them?

Good question, depends on the type. I generally use a mixture of drives and
disks. You should keep them in a safe place, probably not in the same area as
the computer. In case of a fire or burst pipe. You might loose the computer but
not the backups on a shelf down the hall. A fireproof safe would be nice if you
got one.

Remember, while it can be secure on your computer behind passwords and access
controls. Once your data is backed up there is no protection. Although you can
backup encrypted user files with luck and decrypt them after restore. Such as
ones Documents. If your backups contain sensitive information be _sure_ to keep
them in a secure location. It can be just as easy for a smart thief to restore
a backup of yours on his/her computer as it is for you. If given access to the
backup media.

When to backup ?

The question is how much could you afford to loose? If you work on files
often such as a writer, programmer, or an artist. You might want to backup
daily. If your a casual user more worried about bookmarks and mailboxes. Ever
two weeks to two months might do it. Really your the only one who would know.

If you want to automate the task we will be looking at tools meant for that

What to backup ?

This is all a matter of personal preference. The most important things for the
desktop user are files. Namely one would rather save a few 1000 family photos
then installed software that can be reinstalled. My suggestion is at the bare
_minimal_ that you backup your home directory and any major file storage
folders or collections.

System configuration can also be important. Maybe you had to make some changes
to get your system working right or theres just some stuff you don’t want to
tinker with again. Hopefully you did write down any changes you had to make,
like wireless configuration details e.t.c. But a backup never hurts ! I’d
suggest you backup the /etc directory, the loader.conf file and modules
directory in /boot/ if you have drivers there, as well relevant directories
under /usr/local/ if your software requires it (like global configuration
files). It might also be of interest to grab the /var directory and system logs.

At best


What to backup to!

Any proper safe location. If you do use a tape drive, I suggest you take _good_
care of the thing and don’t use it very often. If you don’t know what tape
drives are don’t worry, I’ve never used one ether.

The best storage medium you can get would be CD-R, DVD-R, CD-RW, DVD+R, or Hard
Drive. You will need a burner to write files to a disk but heres a run down.

CD-R, needs a CD Burner. Holds about 650MB of data and files burned to it are
stored for as long as the disk lasts.

CD-RW, needs a CD Burner, works just like a CD-R but you can erase files from
itand reuse the disk. Costs a little more but can be well worth it.

DVD-R / DVD+R, needs a DVD burner but tends to hold much more data, a bit over
4.3GB or over 4,400 MB. Most burners to day support both -R and +R formats, I’d
suggest DVD-R but what ever your systems support.

There are also DVD-RW and Dual Layed DVD media that your drives may support. A
DVD Burner will also burn CD-R and CD-RW 🙂

Another good medium is the external USB hard drive or large capacity USB
sticks. These are good in that they can be used just like hard drive space, but
taken else wheres for storage. If you often use a USB stick for file shares,
you should back it up as well in case of loss or damage.

You can also use hard drives, if you have several computers a reliable one can
be tasked with a high capacity hard drive for the purpose.

My greatest fear is generally for hardware failure rather then accidental
deletion, I’m kinda careful. So I generally make use of hard drives then
optical media for storing long-term backups.

How to backup ?

Interesting question, lets think a few. We have a few options we can

Archive the whole system and stick it some where safe.

Take a snapshot of the file system, good if your prone to erasing stuff

Copies of the disks, poor mans RAID.

If for some reason you are working with a Database, stop the thing before you
back it up. Or at least check the documentation on it before backing it up.
Trust me you don’t want to break that local copy of a website your developing
do you ? Hehehe. Our major software will be dump, cpio, and a few
archive/compression systems.

Dump, the real way to backup a toilet bowl !

Sorry just had to say it. Dump writes raw data blocks that make up
files/folders I’d suggest reading the man page on dump(8) and restore(8) if you
have need of it use it. If you know how to, I’d really say use it. The manual
pages are very good but feel tape-drive centric. Perhaps some one with more
experience with dump/restore can provide better info.

Here is a
good article

If you don’t understand a lick of that or the manual page, do not bother with
dump unless you have to. Trust me, you’ll only get a headache. Learning the
details of dump/restore is also on my to do list.

That being said, dump and restore are probably the _best_ thing you have in the
arsenal of backup and restore tools.

Tar and Friends, the zippy way.

This is probably my most used method and it should prove usable for most
desktop systems. The basic idea behind tar is you take many files and create
one. For example tar can take the files tom, dick, and harry. And turn them
into the file ‘names.tar’, when unpacked you get your tom, dick, and harry
files back. The problem here is tar does not compress data to save space. For
this if we are not working with just a few small files. We probably want to
archive it with tar, then compress it using a program like gzip or bzip2.

PC-BSD uses BSDTar but includes GNUTar as tar and gtar respectively. See the
man page tar(1) and the info file on tar (GNU info page). If your used to
advanced tar usage under GNU/Linux you might find gtar more to your liking.
For basic usage the differences are not worth noting.

We can create a tar archive like so in the konsole

tar -cf files_to_add tarfilename.tar

If we want to be quick about compressing this file we can do it in one line and
use ether gzip (tar.gz) or bzip2 (tar.bz2) like so:

tar -czf filename.tar.gz files_to_add
tar -cjf filename.tar.bz2 files_to_add

GZip is faster but BZip2 may offer smaller files but use more resources when
dealing with bigger files. One can also backup over the network using ssh or
rsh if necessary. For simple usage like this we can use the graphical program
‘ark’ but it may take longer to process the operation (imho). To extract the
files we can open it in ark and extract it or simply run

tar -xzf filename.tar.gz
tar -xjf filename.tar.bz2

A quick and dirty way to back up ones home directory would be to run ark as the
root user from the run dialog or konqueror in super user mode. Add the folder
/usr/home/ to a new archive of given format or to create it like so from
a root konsole.

cd /usr/home
tar -cpzf Terry home-Terry.tar.gz

That is, create a tar archive of my home directory, preserve my file
permissions, and gzip it from the file ‘Terry’ in the current directory.

A far bit of warning, the manual on tar will make your eyes bleed so its
probably best to look for examples or use ark until your used to the command.

See Pee Eye Oh, I see you.

The program cpio or ‘copy input / output’ is the backup tool I recommend along
with pax. Its usage is more complex then tar but more useful. The version
included with PC-BSD/FreeBSD is GNU cpio.

A simple way to create a file with cpio from a konsole is like this

find ./ -print | cpio -vo –format=crc > filename

Will make a ASCII cpio archive in the new portable SVR4 format with a checksum
of all files/folders in the current directory. To restore it to the current

cpio -vidm < filename The v option means be verbose, that is show us what its doing. The -o option is create, -i is extract. -d is make directories as needed, -m is preserve modification times, and --format= is the archive format. Thumb
around the manual page for more details. Sadly this lacks compression 🙁 The
sysutils/afio port is an updated cpio program with more options including built
in compression.

Any one seen K-PAX?

Since the many versions of tar and pax in use by commercial UNIX and Free Unix
likes such as HP-UP & Solaris on one side. And GNU and BSD on the other
userland side. Have various compatiblity issues from time to time. POSIX UNIX
standards people. Created their own program called ‘pax’

If your prone to ‘Distro’ hopping or having to deal with several different Unix
systems you probably would prefer pax to cpio. Dru Lavigne has a great article
about it, so rather then write about it I suggest you read

Heres a simple usage of it just for the same of this document.

pax -wf archivename /what_to_archive

cd /where/to/restore/to
pax -rf /to/archivename

Direct Device Access
dd(1) is a utility to convert and copy files. It has more use then it sounds
really. dd is a powerful tool and a dangerous one. If your not used to it,
please don’t make a typo trust me it could be bad. This program can do some raw
disk copy jobs and even has use in computer forensics to get byte exact copies
of drives. It is also some what hated in that it is used very diffrent from
other UNIX programs. Rather then -options you use a option=value method for
setting options. Here is a demostration of coping a mounted floppy disk in drive fd0.

dd if=/dev/fd0 of/tmp/floppy.image

Which very well may take awhile, we can add the obs= option to write
‘bytes’ at bytes at once and ibs= to read at ‘bytes’ at bytes per once.
Or we can just use the bs= option to set both the same. Thus to speed up

We now have a copy of the sucker as I’ll show with the file and Disk Usage

file /tmp/fd.image
fd.image: x86 boot sector, code offset 0x3c, OEM-ID “BSD 4.4”, sectors/cluster 8, root entries 512, sectors 2880 (volumes <=32 MB) , sectors/FAT 2, serial number 0x742c15e2, unlabeled, FAT (12 bit) du -h /tmp/fd.image 1.4M /tmp/fd.image I only had 96K of data on the floppy but it is a byte for byte copy of the disk. So the image is a full 1.4 megs. Now I will copy it to another blank disk, raw. At approx 16 Kilobytes per. First unmount the disk and insert a blank floppy. dd if=/tmp/fd.image of=/dev/fd0 bs=16384 Now we can mount it and bingo its the mirror image of our old disk complete with the free space on it. mount_msdosfs /dev/fd0 /mnt/fd0/ We can even use rsh or ssh to do this over a network. Remember if you want to 'dd' an image of your hard drive. It will be the same size. For example if I used my systems ad0s1a partition as the In File (if=/dev/ad0s1a) and my ad0s1a partition is 7GB in size with 4GB free space and 3GB used space. The resulting image would be 7GB in size _not_ 3GB. So one must have space to store the image. You would probably be better off with dump but dd has its value. Since dd will probably need to be run as root for much of its usage as a backup tool. I suggest that you _read_ this section of Wikipedia on *WHAT NOT TO DO WITH DD* before using the command and erasing data instead of cloning it! dd

Once PC-BSD has released a GUI program for making backups things will get
simpler. In the mean time here are some ports you might research:

rchivers/mtf             A Unix reader for the Microsoft Tape Format used by NT Backup
archivers/rvm An archive manager that uses rsync to manage backups
databases/usogres Real-time backup utility for PostgreSQL
deskutils/multisync-backup Multisync backup plugin
emulators/vmsbackup Reads VMS BACKUP tapes
misc/afbackup AF's backup system
misc/afbackup-client AF's backup system
misc/afbackup-server AF's backup system
multimedia/streamdvd A fast tool to backup Video DVDs 'on the fly'
palm/pilot-link PalmPilot communications utilities (backup/restore/install/debug/...)
sysutils/afio Archiver & backup program w/ builtin compression
sysutils/bacula-client The network backup solution (client)
sysutils/bacula-client-devel The network backup solution (client) - DEVELOPMENT Version
sysutils/bacula-server The network backup solution (server)
sysutils/bacula-server-devel The network backup solution (server) - DEVELOPMENT Version
sysutils/be_agent VERITAS Backup Exec (tm) UNIX Agent
sysutils/bksh Backup-only shell
sysutils/boxbackup An open source, completely automatic on-line backup system for UNIX
sysutils/cdbkup Simple but full-featured backup/restore perl scripts (uses gnu tar)
sysutils/cpbk Backup Copy programm
sysutils/dar A full featured command-line backup tool, aimed for disks
sysutils/dirvish Network backup system based off of rsync
sysutils/duplicity Untrusted backup using rsync algorithm
sysutils/dvdbackup Backup content from DVD to hard disk
sysutils/flexbackup Perl-based flexible backup system that can use dump/afio/cpio/tar/star
sysutils/fsbackup File system backup and synchronization utility
sysutils/hdup The little, spiffy, backup tool
sysutils/kdar KDar is KDE-based backuptool using libdar
sysutils/pdumpfs A daily backup system similar to Plan9's dumpfs
sysutils/pdumpfs-clean A utility to clean up old backup files of a pdumpfs archive
sysutils/rdiff-backup Local/remote mirroring+incremental backup
sysutils/rdiff-backup-devel Local/remote mirroring+incremental backup
sysutils/reoback Simple but flexible ftp/nfs backup script

Some links that may be of interest

testing the backup utilities

FreeBSD Backup Strategies
FreeBSD Backup Basics