Linuxgruven > Projects > Shell Scripts > Backups with Dump

Backups with Dump


I needed to perform backups at work. My boss suggested that Ilook at dump. (A piece of software that has been a part of Unixsince the beginning.) Here's a brief summary of exactly how I domy backups. This is mostly for me, but I thought others mightalso like the brief rundown.

I back up from /dev/hda1 to a disk mounted at /disks/sda1. hda1is a 40GB partition with Xandros/Debian on it. At the time ofwriting, 4.7GB are used, the full dump compresses down to about2.6GB. The incrementals, of course, depend on my usage throughthe week. Weekly incrementals let me restore to any point duringthe previous week. /disks/sda1 is a 120GB firewire drivethat I use mostly for backup purposes.

My backup system consists of a directory, /disks/sda1/Backup/, a script(backup.sh listed below) and full and inc dump files.

NOTE: dump and restore are part of Debian/ubuntu's "dump" package. apt-get install dump.

Here's the script:

/usr/local/bin/backup.sh



#!/bin/bash
#
#
############################################################
# Simple backup script to dump from hda1 to a file on sda1
# in my case, I'm syncing a 40GB /dev/hda1 partition to a
# firewire drive living on /dev/sda1.
#
# Dump records are stored in /var/lib/dumpdates on Xandros/Debian
#
# This script was inspired by the RHL9 Bible page 460
############################################################
# ** Sample command **
#/sbin/dump -8 -u -j -f /disks/sda1/Backup/full_0.dump /dev/hda1
#
# ** DUMP Options: **
# -$level = dump level
# -u = update /var/lib/dumpdates
# -j = compress
# -f = dump to file rather than to device
#

if [ $1 ]; then
level=$1
else
# No dump level specified, assume 0 (Full backup)
level="0"
fi

# Some variables:
sourcePartition="/dev/hda1"
destDir="/disks/sda1/Backup"
dumpOpts="-$level -u -j -f"
dumpExec="/sbin/dump"

if [ $level = "0" ]; then
# Set file name to full_0.dump
dumpFile="full_0.dump"
else
# Set file name to inc_$level.dump
dumpFile="inc_$level.dump"
fi

finalCommand="$dumpExec $dumpOpts $destDir/$dumpFile $sourcePartition"

echo "Going to run $finalCommand"

$finalCommand



Once this was done, I then added this to root's crontab. (Typecrontab -e)

Add the following to the crotab file:

0 22 * * 0 /usr/local/bin/backup.sh 0
0 22 * * 1 /usr/local/bin/backup.sh 9
0 22 * * 2 /usr/local/bin/backup.sh 8
0 22 * * 3 /usr/local/bin/backup.sh 7
0 22 * * 4 /usr/local/bin/backup.sh 6
0 22 * * 5 /usr/local/bin/backup.sh 5
0 22 * * 7 /usr/local/bin/backup.sh 4
This will cause the backup script to run every night at 10:00. OnSunday it will do a full backup, during the week it will doincrementals.

Restoring


To restore, all I would have to do is type:

mount /dev/hda1 /mnt
cd mnt
restore rf /disks/sda1/Backup/full_0.dump
restore rf /disks/sda1/Backup/inc_4.dump

where /disks/sda1/Backup/ is where the dump files live, and inc_4.dumpis the last incremental I've got. Because I use decreasing dumplevels, I only need to use the last incremental. (Eachincremental contains all changes since the full backup.)

:wq