Adverts

Now that I am the proud owner of a DVD writer it is time to get doing some backups. I have bought twentyfive DVD-RW disks to perform the backups on. Twenty will be used as nightly backups and 5 as monthly. Not quite a standard set up but good enough for what I want (chosen for me because you can easily buy packs of 25 DVD-RW and they are quite cheap). I suppose I could use some fancy backup software but to be quite honest it probably would do everything I want and it would take about as long to learn how to use it as roll my own. So here goes...

First get hold of the tools you will need. The dvd tools package is a must (I am using "dvd+rw-tools (5.17.4.8.6-1)" at the moment) since it provides useful tools for burning DVD's correctly. The k3b package also comes very highly recommended, although it is of less use for an automated backup. I am going to be using a 2.6 kernel on Debian testing which means I won't need to use the ide-scsi interface layer (a good thing). If you are using a 2.4 kernel (or earlier) you will have to make sure this is installed other than that though everything should work the same. The disks I am using are no name 1x speed DVD-RW because they are cheap. I don't really care if the back up takes a couple of hours to burn the disk because it will be taking place in the middle of the night as a cron job. I also felt it wasn't worth investing in the (slightly) more expensive DVD+RW since I will just quick erase the disk each night before doing the back up. Apparently the largest file that can be burnt onto an ISO9660 disk is 4GB but this can be overcome if you switch off Rock Ridge and Joliet and use a plain UDF file system which will let you burn a single file of upto 4.4 GB (or the capacity of the disk).

Update: The no-name DVD-RW disks were a pile of the proverbial and generally failed after one write (they couldn't be over written). I have since coughed up some cash and bought Packard Bell DVD+RW disks that allow for 2.4 speed writting. They seem to work for multiple re-writes. You will probably want to check out this site (videohelp.com) which lists media that works with numerous drives.

Tools of the trade:

growisofs

Useful argument for growisofs are:

Since growisofs is a pretty wrapper for mkisofs you can use essentially all the options of mkisofs as well.

mkisofs

We won't actually use mkisofs directly but we can use its options in growisofs. Useful options include:

tar

Since I want to be able to make sure that I capture the directory structure and files names as well as the data it is not a good idea to just burn the individual files since even with Rock Ridge extensions in use you can't have more than 8 levels of directories and various other strange restrictions. Hence I am going to tar up the files I want to burn and then burn the tar. This also means that if I end up in the situation where I am having trouble fitting the back up on the DVD (really this might happen - one day) I can easily just gzip / bzip the tar.

cp

Allows us to copy portions of the file system from one place to another.

pg_dump

We want to be able to back up the database as well as the basic files and this is best done using pg_dump which will write the database out as a simple sql file. You have got to make use that the user that is running the backup job has permission to dump the database.

The Backup Script

Note: The line starting SOURCE is actually one long line that includes all the lines that follow upto the next blank line as indicated by the ↳ symbol (should be a downwards arrow with tip rightwards).

#!/bin/bash
DATE=$(date +%Y-%m-%d)

#NOTE: These two paths must end in a / in
#order to correctly build up the other paths
BACKUP_DIR="/backup/directory/"
TEMP_BACKUP_FILES_DIR="/backup/temp/"

BACKUP_FILE=$PATH"backup-"$DATE".tar"
DATABASE_FILE=$TEMP_BACKUP_FILES_DIR"foo-"$DATE".sql"

#These directories shouldn't end in a / although
#I don't think it will cause any problems if
#they do. There should be a space at the end though
#to ensure the database file gets concatenated correctly.
SOURCE="/a/location /other/locations " $DATABASE_FILE

echo Removing old backup directories
rm -rf $BACKUP_DIR
rm -rf $TEMP_BACKUP_FILES_DIR

echo Creating new backup directories
mkdir $BACKUP_DIR
mkdir $TEMP_BACKUP_FILES_DIR

echo Creating database backup
pg_dump -U username -f $DATABASE_FILE databaseName

echo Backing up $SOURCE to file $BACKUP_FILE
/bin/tar -cpf $BACKUP_FILE $SOURCE

#This is not necessary and possibly harmful for DVD+RW media
echo Quick blanking media
dvd+rw-format -blank /dev/hdc

echo Burning backup
growisofs -dvd-compat -Z /dev/hdc -r -J $BACKUP_FILE

Testing the Backup

From time to time it is a good idea to test your backup to make sure you can actually recover data from it. A good time is when you are sure it's working a bad time it when you have to get something you just deleted off it!

First mount the drive

mount -f udf /dev/hdc /mnt/dvd

then copy the tar file to where ever you have space to expand it

cp backup-file.tar /big/drive/

move to where you have copied the file and expand the tar with

cd /big/drive
tar -xf backup-file.tar

be careful you don't type a c where the x is in the tar command above or you will have to copy the file over again! Finally check that all your files are there and readable.

Adverts

Donate and Help

Please support this site and
Bandwidth doesn't grow on trees y' know :o)

Adverts

Get Adsense