Mon, 17 Apr 2006
The other day I mentioned to a client that any lost files could be restored from a backup. The client stared at me blankly as if I had just spoken another language. I often lament that people that use computers should take the time to learn a thing or two. Not for my benefit but, for their own. Backups are a fine example. Would you live your life without car or house insurance? How about mortgage or life insurance? Most of us pay for at least one these yet almost no one has computer insurance. Take a minute to think about all of the data that is currently on your computer. My list includes:
This is by no means an exhaustive list. Now, imagine that all this data on your computer is suddenly gone. Forever. How much would you pay someone like me to get at least some of this data back? Believe me when I tell you that, in some cases, this could cost thousands of dollars. In other cases no amount of money will ever bring your data back. For some of you this will be a minor annoyance. For others, it could be a life altering event. Most people do not realize is that, a few minutes of work a week could have minimized this loss.
The concept of a backup is simple. Make a copy of all your important files and store them in a safe place. It is so simple yet, so overlooked.
What to backup
As we know from our imagined list of data, there are many files to be backed up for safe keeping. Often, I find clients do not even know where these files are stored. If you do not know the answer to this question you need to find out. It is your data. Only you know where you put it. Generally there are only a few considerations. Directories like My Documents and Favorites are pretty common among Windows flavours. Other web browsers, like Firefox, have their own profile directory which will contain bookmarks. Email clients similarly store email in profile directories that are predetermined or set by the user. You will have to research to be sure. The next time you save or open things, notice where they are.
Unix, systems tend to be a little easier. Normally, /home/<username> contains all of your data. Some of it may not be needed. If you are the administrator, then it is useful to backup /etc as well as other locations such as apache pages, mail spools and server logs.
When to backup
When you backup depends upon how often your data is changing. A busy person may like to backup work daily. A good rule of thumb is to backup at least once a week. Personally, I backup locally every day and create off site backups once a week.
Where to backup
I have three different backups. A nightly backup that I store on the same hard drive. I use this one to quickly restore any files that are accidentally erased. Weekly, I take the latest nightly backup and copy it to a USB key and to a server in a different location. Keeping a backup separate from your computer is paramount. If your hard drive fails, you will need independent storage, like a USB key from which to restore your data. Off site backup is the most secure. Storing data in a safety deposit box or a remote server allows you to restore data even after a catastrophic event like a flood or fire. Other types of backup media include tapes, CDROMs and DVDs.
Storing your data remotely means that it may not always be free from curious, prying eyes. I recommend encrypting your remote backups.
How to backup
Here is an example of a Unix backup policy:
Nightly backup
This script stores all my important files on the same hard drive. It runs automatically every night using a crontab.
#!/bin/bash
#backup for local.example.com
cd /opt/backup
# backup all mysql databases
/usr/bin/mysqldump --quick --all-databases -u root -p*$passw0rd > /opt/backup/nightly-mysql_dump
# backup selected system files
tar -cjf etc-nightly.tar.bz2 /etc
tar -cjf apache-nightly.tar.bz2 /var/www
tar -cjf local-bin-nightly.tar.bz2 /usr/local/bin
tar -cjf kernel-nightly.tar.bz2 /usr/src/ettin*
tar -cjf misc-nightly.tar.bz2 \
/usr/kde/3.3/share/config/kdm \
/opt/music/playlists
# backup files from my home directory
tar -cf johndoe-nightly.tar \
/home/johndoe/Mail \
/home/johndoe/docs \
/home/johndoe/.blackbox\
/home/johndoe/.config\
/home/johndoe/.gaim\
/home/johndoe/.profile\
/home/johndoe/bbrc\
/home/johndoe/.*rc\
/home/johndoe/.kde/share/apps/kabc/std.vcf\
/home/johndoe/.kde/share/apps/kabc/distlists\
/home/johndoe/.kde/share/apps/korganizer/johndoe.vcs\
/home/johndoe/.kde/share/config\
/home/johndoe/.ssh \
/home/johndoe/.Xdefaults\
/home/johndoe/.vim
# back my bookmarks
find /home/johndoe/.mozilla -name bookmarks.html -exec cp {} johndoe-bookmarks.html \;
# change permissions and compress the backups with bzip2
chmod 640 *.tar
chgrp wheel *.tar
bzip2 -f *.tar
# email backup report
ls -l /opt/backup|mail -s "backup results" johndoe@local.example.com
Remote Backup
Weekly, I copy these files to a USB key and to a remote server. They are moved to a remote server via ssh and encrypted using SSL,
#!/bin/bash
#remote backup for local.example.com
# enter passphrase for encryption
echo "Enter openssl passphrase: "
read -s SSLPASS
# copy files and encrypt via ssl
cd /opt/backup
find . -type f -print |
while read file
do openssl enc -blowfish -k $SSLPASS -in $file | ssh jdoe@remote.example.org "cat > /home/jdoe/backup/$file.blow"
done
# email backup report
ssh jdoe@remote.example.org ls -l backup|mail -s "remote backup results" johndoe@local.example.com
# to decode
#openssl enc -d -blowfish -in |tar -tjf -
Windows users I haven't forgotten about you. Microsoft's website is a good resource for backups and other topics. Windows XP Backup Made Easy describes how to backup files on your Windows system. My research was not able to discover a reliable method to encrypt your backup. If you know of such a method please contact me.
At first backups may seem like alot of work. Once your backups become habitual you'll hardly notice the extra work. Should you ever need to recover your backup the extra work will pay off. Be safe. Be secure.