Linux Workstation Backups -- Without TearsLinux Workstation Backups -- Without Tears
Building a bootable clone drive and DVD-R backup archives can make the difference between inconvenience and disaster. Learn how to execute flawless backups, even if you're a Linux newbie.
How To Archive to DVD-R
There are many backup programs available for this task. But, unfortunately, most require complex installation or configuration. Instead, we need something that is suitable for a Linux novice, a tool that separates creating DVD-sized files from burning them to DVD-R, and that compresses individual files, not directory trees. This way, a disk-media defect will kill just one file, not the entire backup.
Archiving, compressing, and burning-in separate operations avoids the need to spend hours baby-sitting the computer, waiting for it to demand yet another DVD-R. Instead, this procedure first makes DVD-sized archives. Then you burn them to DVD-R as quickly as the computer can create the DVD images. This is still time-consuming, but the only faster alternative is to use a DVD autoloader or DVD library system that costs thousands of dollars.
dar is a Linux hard-drive backup program that creates archives the way described above. It's easy to install and highly functional.
But using dar requires that you have enough space on the hard drive you are backing up for all the DVD ISOs plus some working room to allow for the creation of the temporary files associated with the process. For example, if you're backing up 20 GB of actual disk usage, you're going to need at least 15 extra gigabytes of hard drive space to make this work. When in doubt, get a bigger drive. Hard drives are still cheaper than your time.
Note that the backup and compression process will be extremely time-consuming. This is one of those processes you want to start, then let run overnight. It's also CPU-intensive; while it runs, you can't do anything else with the machine.
As the next screenshot shows, the process labeled 3 (dar) -- indicated by the arrow -- in the terminal window displayed by the top command was only running at 72.2% CPU utilization when the shot was taken. At other times, however, it frequently went over 90%.
I'm assuming a DVD-R drive in the following. Even a minimal personal workstation configuration is too large to record onto any reasonable number of CD-Rs -- especially if you have transitioned an old Windows box onto Win4Lin and ported all personal/business files into the Linux environment. If you are using a tape drive, then there are many tutorials available on the Web, and Google can find them for you. Let's get started:
Download dar: You can get it here. Find a binary that'll work with your distribution at the links from the download page. Install dar: rpm -i dar-2.1.1-0.2.i686.rpm It appears that dependencies aren't a problem for it. Create a backup directory: mkdir /usr/local/backups -------------- start here #!/bin/sh #/usr/local/bin/dar_backup.sh echo "Executing archival backup script" cd /usr/local/backups dar -z5 -s 1900M -D -R / -c 'date %5C -I'__data -Z "*.gz" -Z "*.bz2" -Z "*.zip" -Z "*.png" -P tmp %5C -P dev -P proc -P mnt -P sys -P selinux -P usr/local/backups ------- end Next, open a text editor (nano will do): nano /usr/local/bin/dar_backup.sh Highlight everything between "start" and "end" above. (That is, the first highlighted character should be '#', and the last character should be the S in "backups".) Copy the above script to the clipboard, and paste it to the text editor.
How the DVD-R Archive Works
The script is a version of a sample dar command line to be found in the third-party dar tutorial DAR differential backup mini-how-to. I've modified it to fit a workstation environment. It's a good idea to grab a copy of this page to add to your backup documentation for your DVDs.
Each line portion of the dar command above is ended with a backslash.
That's because the dar command is a single line; the backslash tells the terminal that what follows is part of the same command line.
The main command line switches are:
-z compress - warning: The default is maximum compression, and running it this way pushed my CPU utilization to over 90%. -s 1900M: This splits the backup file length into 1900 MB. This means that you'll be burning two archive files per disk. While 4000 MB to fill the DVD-R with one backup file would be preferable, not all Linux software deals reliably with 2000 MB plus individual files. If you have radically different sized backup media (for example, if you are burning to CD), then change this number to fit. -Z: Do not compress this file (or file type). Running a second compression over an already compressed file burns CPU time and often increases the file size. [-c 'date -I'_data tells the program to create a backup filename based on the current date plus _data. This is where the 2004-10-13_data master backup data name comes from, as you see it below, the current date++ _data. -P means "exclude this directory tree." Add directories to exclude as necessary.
The following is a backup procedure for use once the program is installed and the hardware is set up. It can be copied-and-pasted into an alert/reminder program the same way the COMPLETE BACKUP procedure above can be.
Your backup files will appear in /usr/local/backups in compressed 1.9G "slices" with a filename based on date/time:
2004-10-13_data.1.dar
2004-10-13_data.2.dar
2004-10-13_data.3.dar
BURN!!!
These instructions are for a stand-alone workstation.
To burn CD/DVD backup to write-once (CD-R, DVD-R) or reusable (CD-RW / DVD-RW), you need to install a CD/DVD burner program if you don't already have one. And, of course, you'll need a CD or DVD burner.
If you do have a burner program, skip to the section "How to Burn Archives to DVD-R" below, and copy the files specified below into your DVDs. I used K3b as a GUI interface to cdrecord, which is included in most Linux distributions.
Install CD/DVD burner software
For users of distributions that support either yum (Fedora Core) or apt-get (Debian) automated installation methods, this is for you.
This is how a modern application is supposed to be installed. The K3b team recommends the use of yum or apt-get and has their own repositories on-site to support these installers.
First, go to the k3b site and cut-paste the configuration information into your yum or apt-get configuration file. If you need help, the process is explained on this k3b download page.
Next, login as root, and then:
yum install k3b
or
apt-get install k3b
When the first and second text prompts come from the yum installation program -- "Do you want me to install (or download) ? y/n" -- type Y for yes. Otherwise, the program you want won't install.
If you're running Fedora Core 2 and you see a lot of error messages referring to the /selinux directory tree, ignore them. It's a "not implemented yet" part of that distribution; they generally indicate that the program is installed normally.
After installation, open k3b in KDE menu > Sound & Video > CD & DVD Burning. If it doesn't show up there, open a terminal and type: k3b
How to Burn Archives to DVD-R
You will generally be burning a pair of 1.9 GB archive files to each DVD-R. If you are not using k3b, the interface will differ, but you will be able to do substantially the same things described here.
The Currents Projects subwindow is shown in the following DVD burner program screenshot. It shows what you should be burning to the first DVD-R in your backup set: the first two backup files, backup software, and backup documentation:
Here are the steps for burning archives to DVD-R:
Open New Project by selecting it from the top toolbar. Via the file window, change directories to /usr/local/backups. Drag in the first (2004-10-13_data.1.dar) and second (2004-10-13_data.2.dar) backup file. Get the dar rpm installer file from wherever you downloaded it to. I recommend that you save a copy of this article, too. The dar documentation is in /usr/share/dar, and it's quite good; grab the TUTORIAL and the README. Drag-and-drop-in whatever docs or programs you want to make life easier when you're ready to re-install. Save the project as BACKUP1, then burn it. Label the volume backup1, and burn it. You'll want to put the dar docs into disk 1 of every backup, replacing via drag-and-drop the actual backup files. If the program complains that you are not running as root, log in as root and rerun k3b Once you are done, close the BACKUP1 project. Open New Project: Drag. Drop the third and fourth backup file, with a filenames 2004-10-13_data.3.dar and 2004-10-13_data.4.dar into the second disk. Note the 3 number; subsequent backup files will be numbered 4, 5, etc. Save the project as BACKUP2.
Burn and label it backup 2 (3, 4, etc.). Repeat Step 2 until all backup files are burned to DVD-Rs.
Next, the following is a backup procedure for use with the program once it's installed and the hardware is set up. This procedure can be copied-and-pasted into an alert/reminder program the same way the COMPLETE BACKUP procedure above can be.
CREATE PERMANENT BACKUP ARCHIVE SET
DO NOT CLOSE THIS ALERT
Commands can be cut and pasted to the terminal.
Open a terminal window. Log in as root: su - root Enter in terminal (processing will take several hours): sh dar_archive.sh Your backup archive files are in /usr/local/backups. Open k3b (or other CD/DVD-R burner program). Open BACKUP1 from your CD/DVD-R burner program. Substitute first two ( .1.dar , .2.dar) files ending in dar for original dar extension backup files. Do not change other included files. Burn the first DVD-R. Open BACKUP2. Substitute first two (............003.dar ............ 004.dar) files ending in dar for original dar extension backup files - do not change other included files. Continue to burn pairs of .dar files (005,006. . .) to DVD-R until you run out. Erase dar files : cd /usr/local/backups and enter: rm -rf *.dar Remove DVD-R backup set to safe place or offsite. Close this alert.
Reminders
Of course, the best time to make a backup is when the machine is loaded as lightly as possible. Also, if a file is changed during the course of a backup, the likely result will be a corrupted file. To avoid this problem, instruct your clients to either back up their files during lunch or run a full backup overnight, whether to backup drive or by creating the files for an archival DVD-R.
But no backup program will work if the user forgets to run it. Most Linux distributions come with an alarm/timer program called KAlarm. This will put a reminder based on text you entered at the time/date specified, or at daily / monthly / weekly / yearly intervals.
To use reminders, in the KDE Menu, go to Accessories > More Accessories > KAlarm (Personal Alarm Scheduler) . If it isn't in the menu, check Add/Remove Applications or your distribution's equivalent to see if it can be automatically installed from your distribution's ISOs. If all else fails, go to this KAlarm page, and look for a version that works with your distribution.
From the Settings > Configure KAlarm, click Run Continuously in System Tray / Autostart at Login / Warn before Quitting as in the image below. This will ensure that the reminders will be available whenever your user starts her computer.
To set up an alert, either click New from the top toolbar or right-click the alarm icon in the System tray and then click New. Next, enter the text of the message. In this case, you will see the Incremental Backup procedure as cut-and-pasted from article. Next, enter the date and time. Click on Confirm Acknowledgement.
To set recurrence, click the Recurrence top tab:
Incremental backups are set here on a weekly basis: Monday, Wednesday, and Friday. This screen shot shows how the alert will look to the user:
Restore
Finally, let's restore to a test directory. For a bare-metal post-crash install, do a minimal install of a Linux distribution -- preferably the one you were previously running -- so you have an environment to run dar in. Print copies of the backup documentation from the first disk, including a copy of this article. This is in case you want to do something other than a full restore with overwrite of all files from your DVD backup set.
Next, copy the compressed backups from DVD and the documentation:
/usr/local/backups
Install dar as above. If that doesn't work, try copying this:
dar_static
into
/etc/
Then run
/etc/dar_static
in place of dar in the line below:
dar -x /usr/local/backups/2004-10-13_data -R /usr/local/backups/test
The above command is a single line you can copy/paste into a terminal window. Substitute the directory name wherever you want to put the restore for /test and your actual filename for 2004-10-13_data. Add -w to the end of the command line if you wants to overwrite without warning. That is, if you are restoring straight to / ... add -b to the end of the command line "do not overwrite files later than archive being restored".
Once the restore is complete, copy the files to the respective directories for your home directory:
cp -au /usr/local/backups/home /home
This lets you be more selective about copying files and directories. But if space doesn't permit, you can simply copy it to / and overwrite. But do read the tutorial docs before doing anything that hasn't been described here. It's only your client's data (or your own) that's at stake!
A. LIZARD is an Internet consultant in the San Francisco Bay Area. He has been writing for technology magazines and Web sites since 1987. What did you think? Discuss this Recipe with other system builders in the TechBuilder Recipe Forum.
About the Author
You May Also Like