horns
GreasyDaemon.com - Your Guide to BSD Unix home - news - directory
FreeBSD OpenBSD NetBSD MacOS X Daemon News OpenBSD Journal
Backups with BSD

Backups are not rocket science. You simply want to make a redundant copy of your critical files in case the originals are lost due to theft, fire, or anything conforming to Murphy's Law. A backup of your critical files can take many forms. You can simply copy your files to another server, burn a CD with your files or drop all your files to a tape which will hold everything on your system.

I currently use all three methods. Multiple redundant backups are your best friend in times of need. What is best for you? Do you really need to do the backups? This all depends. If you have plenty of space where you can put your backup, then doing so should not be an issue. I will cover 3 ways to back up your system. Given these examples you should be able to come up with a plan for your backup scheme.

Method 1: Archive and Transfer

These days it is very inexpensive to purchase a very large IDE drive. For a few hundred bucks you can get a drive which will hold beyond 20 gigs of storage. With that you can tar and gzip your critical files, like /etc, /home, and others. You do not need to archive every file, just the ones you cannot restore easily upon rebuilding your system, meaning user and configuration files. Once you have selected which files you will archive, you can use tar and gzip to create archive files. The following command will archive /etc /home and /export to /backups/archive.tar.gz.

tar -czf /backups/archive.tar.gz /etc /home /export

This command compresses the archive while is creates the archive file. You may be able to compress your files by half their size, but that all depends on what kinds of files you are trying to compress. After you run your first archive you will have an idea of the compression rate you can expect. This command places the archive file in the /backups partition, a drive you would want to add to your system to hold this archive. This can be a large IDE drive. Perhaps a $150 18 gig drive will do the job for you. You do not need to have this drive to run this archive, but it is useful to ensure you will always have the necessary space.

Now that you have a copy of your critical files you want to protect that archive. Having it in the same machine in the same location does not offer much security. What you want to do is set up a machine at a different location to pull the archive file. You can automate this with a simple perl script. (getarchive.pl) Configure the getarchive.pl script and run it routinely with cron. You can set the archive command to run nightly at 1am and set the remote server to grab that file at 4am when you know the archive has been safely completed. To learn more about cron, read the crontab(1) man page. (man crontab) You can also set the cron job to rename the archive monthly so that after a few months of archiving has gone by, you will have the ability to restore archives from different time periods.

Advantages of Method 1

Method 1 keeps backups running nightly on the same box as the original files. Having recent backup readily available is useful. The files also are moved to another location to protect against theft or damage of the original files. This can be enhanced by having the files copied to more than one redundant location. Finally, having archives named by month you can go back to a specific time period and pull files which you may need, like configuration files you used 5 months ago but deleted because you thought you would not need them again, but now you do.

Method 2: Burn a CD

Burning a CD with your important files can be a powerful backup option if you do not have very many files to back up. The commonly used CDs hold only 650mb of space and are write once disks. Newer disks can hold more and can be re-written, but I will only address the typical 650 write once type, because those are cheap to buy in bulk and that is ideal for backups.

You may have more than 650mb of files to archive, and that is fine. You just have to break them up into workable blocks and keep a schedule to ensure you complete a full backup for each cycle. If a full backup requires 5 disks be burned, you shoud burn 5 disks.

Next you have to do the CD burning. You can use software like cdrecord if you choose to use your BSD box directly, or you can use a Windows machine or a Macintosh to use some of the more elegant CD burning applications available for those desktop systems. Choose which route is best for you. I will not cover cdrecord as I have never had the opportunity to use it. I use a graphical application on an iMac to create CDs on a Sony Spressa USB drive. It works and does the job quickly while the server does what servers do.

Advantages of Method 2

It can be very cheap to do backups on simple burnable CDs. They hold up to 650mb apiece and cost less than a buck. They are also are inherently write only which adds a certain level of protection against altering your backups. Since they are so cheap you can distribute your redundant backups to multiple locations so that you are protected against theft or damage, just like in Method 1. You can also use the CD burner to make music CDs from your B-52's mp3 collection.

Method 3: Tape Backup

Ok, stop wasting your time with these other two methods and just get a tape drive, if you can afford it. The drives can go from $200 to beyond $1000 easily. It all depends on what you need. Assume you get a drive which is $300 and just holds one 20 gig tape. And then assume the drive is a SCSI tape drive. The tapes themselves will cost much more than your average write once CD, but are rewritable.

To run a backup onto a tape drive you can use the same tar command from Method 1, but the target for the archive file is going to be the raw tape device. I created a few useful scripts to work with the tape drive I have running in a server which is now running FreeBSD 3.5-STABLE. Since the tape drive is SCSI, it is very well supported and the following scripts may work with little modification for any BSD system. It all depends on the raw device name for your tape device.

Create the backup
run-backup.sh
Create a table of contents dump (tar tvf)
run-toc.sh
Restore the backup
run-restore.sh

Advantages to Method 3

Running a tape backup is convenient for backing up a large number of files. You just drop everything to the large tape and do it as often as you like. Then you can take copies to remote locations to provide for protection against theft. Tapes are also designed to be very durable. CDs are easy to damage even with the light touch of a pen and harddrives can fail or remote servers can be unreachable.

What is best for you?

What is best for you is what you can determine. You can use all three examples as I do based on what system I need to backup or you can choose one or even a hybrid. You just want to ensure that you restore lost files quickly and completely in the event that your files are stolen or destroyed or otherwise unreachable. Consider this, if your building had a fire on another floor and your office was fine but you were not allowed in the building for a week, would your backup scheme allow you to maintain your production systems? During the months following the World Trade Center bombing companies went out of business because they could not access their data in timely matter. They lost their clients and their revenue stream. Your files are not just files, they are your assets and you need to protect them, even if it is just a very large collection of mp3 files, it takes time to rip all those B-52 songs.

Related Links:

GreasyDaemon.com


FreeBSD
Powered by
UdmSearch
O'Reilly & Associates