Roll your own

Most small installations, and even some of the larger ones, have their own home grown collection of backup scripts to handle automating the task of making backups.

We'll go through the steps briefly of what the script would need to do, and then give an example of what the script might look like.

We want to backup the two partitions (/ and /home) on our server. We have a tape drive in the machine, and a single tape can quite easily hold a full backup for the entire system.

Performing a backup

Procedure 4.1. Steps to backup

  1. rewind the tape

  2. backup / partition using tar

  3. set EOF marker

  4. backup /home partition using tar

  5. set EOF marker

  6. rewind and eject tape

Thus, the commands we would need to issue would be:

Procedure 4.2. Commands to backup

  1. mt rewind

  2. tar cz /

  3. mt eof

  4. tar cz /home

  5. mt eof

  6. mt rewoffl

This could all be easily placed inside a shell script, like this one:

debian:~# cat backup.sh 
#!/bin/sh
echo "Starting backup..."
mt rewind
tar cz /
mt eof
tar cz /home
mt eof
mt rewoffl
echo "Backup complete!"
                

You could easily schedule this script to be run automatically every evening, using the cron command.

Now we need to verify the backup, so that we know that we can actually restore from it.

Verifying Backups

Procedure 4.3. Commands to verify

  1. mt rewind

  2. tar tz

  3. mt fsf

  4. tar tz

  5. mt rewoffl

This will rewind the tape to the beginning, and then stream the first section of the tape through tar, with the "t" (test) switch, which will verify that tar can read the stream. Once that's done, then we use the mt command to position the tape at the start of the next stream (which is our backup of the /home partition), and then we perform another "test". Once we're done, we rewind and eject the tape, and can now store it away and be pretty sure that we can restore from it.

[Tip] Tip

Remember to label your tapes!

Restore from backup

OK, user "Joe" has managed to delete some critical files from his home directory, and he wants them restored. We manage to get the latest tape backup from out of the fire proof safe, and pop it into the tape drive.

Procedure 4.4. Commands to restore

  1. Now we need to rewind it: mt rewind

  2. OK, now we know that the stuff we want is in the second stream (the /home directory), so we can skip ahead to that part of the tape immediately: mt fsf

  3. Once we're there, we can then instruct tar to restore just a specific path of files: tar xf home/joe/important.doc

  4. This will cause tar to seek through the tape stream and only restore the matching files: mt rewoffl

[Tip] Tip

Once we're finished - rewind the tape and eject it, and put it away safely.