I cannot stress how important it is to create backups of your system(s). At a minimum, copy your personal and business data, and configuration files to a safe place. Some people backup everything, even the operating system itself. Whatever you decide to do, make a plan and stick to it. As mentioned in Chapter 8, Working with Scripts, this is a great time to design and use a script. Use crontab
if desired, to automate the periodic taking of backups.
The tar
command is great for backing up entire directories. Note that it will get any hidden files as well. You can exclude specific directories if desired, and do quite a few other things with tar
. The following are the commands similar to the ones I use to backup my /home/guest1
directory.
cat tsback1 0
The following is the start of the script:
cd /home NUM=`cat tsback1` # get the next number to use tar -cvzf /megadrive/backups/backup$NUM.gz --exclude=Cache --exclude=.cache --exclude=.thumbnails guest1
Remember to include the directory to be backed up as the last thing on the line. This first changes the /home
directory, because for tar
, you want to be in the parent directory of the sub-directory to be backed up. The next line sets the NUM
variable to the next one to use. The last line creates the tar
file directly onto my USB external drive in the appropriate directory.
I attempt to be very careful while creating backups. The script I actually use to back things up does quite a few other things. For example, it checks to make sure my USB external drive is really there, and can be written to (it should also check if there is enough free space on the drive, that's a TODO of mine). If the code determines the drive is not there or some other error occurs, a really loud and obnoxious alarm goes off. And, if I have not responded to this alarm in 5 minutes, an email is sent to my cell phone. How's that for paranoid?
Making backups is great. However, if the backup is unusable, it doesn't do you much good. So, it is wise to verify your backups from time to time. How often do this is up to you and your comfort level. My script routinely copies the backup files to another machine, which then extracts them and runs a few tests. If anything doesn't look quite right, another alarm goes off. This is all done automatically in scripts.
Okay, we are now making backups and verifying them. What about storing them? Suppose you have everything just right, all your files are copied and verified, and they are all located in the same place such as your home or office. And now something unspeakable occurs, such as a fire or theft. I agree, there is a very low chance of this happening, but it still could. I, for one, do not want to try and reproduce the million lines of code I have written since 1982 and so have backups all over the place, including off-site. In some of the companies I have worked at, the files were copied to tape, CDs, and/or hard drives, and stored in a walk-in fireproof safe. Pretty good idea.