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.
Procedure 4.1. Steps to backup
rewind the tape
backup / partition using tar
set EOF marker
backup /home partition using tar
set EOF marker
rewind and eject tape
Thus, the commands we would need to issue would be:
Procedure 4.2. Commands to backup
mt rewind
tar cz /
mt eof
tar cz /home
mt eof
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.
Procedure 4.3. Commands to verify
mt rewind
tar tz
mt fsf
tar tz
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 | |
---|---|
Remember to label your tapes! |
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
Now we need to rewind it: mt rewind
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
Once we're there, we can then instruct tar to restore just a specific path of files: tar xf home/joe/important.doc
This will cause tar to seek through the tape stream and only restore the matching files: mt rewoffl
Tip | |
---|---|
Once we're finished - rewind the tape and eject it, and put it away safely. |