On 02/06/11 17:28, Chris Rowson wrote:
I've been tinkering with backups and backup rotation today and I have
come across many wierd and wonderful backup scripts of varying
complexity.

Is there anything wrong with using something simple like this? (except
of course for the lack of validation).

Basically, let's delete anything over 7 days old and then make a new backup.

Hi, Chris.

I use this ETOH (Extended Towers of Hanoi) backup that I contributed to NEBC Bio-Linux. It provides a baseline level 0 dump and three months of incremental backups. You can get it as a deb from NEBC:

  http://nebc.nerc.ac.uk/tools/bio-linux/

Bye,

  Tony.
--
Dr. A.J.Travis, University of Aberdeen, Rowett Institute of Nutrition
and Health, Greenburn Road, Bucksburn, Aberdeen AB21 9SB, Scotland, UK
tel +44(0)1224 712751, fax +44(0)1224 716687, http://www.rowett.ac.uk
mailto:a.tra...@abdn.ac.uk, http://bioinformatics.rri.sari.ac.uk
#!/bin/bash

#Fail on errors!
set -e
set -u

#######################################################################
# /etc/cron.daily/backup - a script to backup one hd to               # 
# another on the same machine, using dump                             #
# (see the dump man page for details, and                             #
# http://envgen.nox.ac.uk/envgen/software/archives/000501.html#auto   #
#                                                                     #
# Written by MIT, 20/6/2002                                           #
# Modified by Dan Swan for Bio-Linux 2.0 17/3/2003                    #
# Updated for Bio-Linux 5 by Tim Booth 1/8/2008                       #
# Updated to perform Quarterly ETOH backups by Tony Travis 17/7/2009  #
# Updated to dump ext4 fileystems by Tony Travis 19/5/2010            #
#######################################################################

# Source configuration file
CONFIG=/etc/default/backup
if [ -r $CONFIG ]; then
    . $CONFIG
fi

#Use basic or ETOH mode?
backup_mode=${MODE:-"etoh"}

#Where to backup
backup_destination=${DESTINATION:-"/backups"}

#What to backup
backup_filesystems=(`echo ${FILESYSTEMS:-"/ /home /var /usr"}`)

#Compression scheme.  For large drives bzip2 is probably too slow.
compression_mode=${COMPRESSION:-"z"}

# get the date
day=`date +%a`
month=`date +%b`
dom=`date +%d`

#Dump level can be set on command line or by todays date.
if [ -n "$*" ]; then
    level="$1"
elif [ "$backup_mode" == "etoh" ] ; then

    # Quarterly Enhanced Towers of Hanoi
    if [ $day == "Sun" ]; then
        if [ $dom -le 7 ]; then
            case $month in
            "Jan" | "Apr" | "Jul" | "Oct") level=0 ;;
            *) level=1 ;;
        esac
        elif [ $dom -le 14 ]; then
            level=3
        elif [ $dom -le 21 ]; then
            level=2
        elif [ $dom -le 28 ]; then
            level=4
        elif [ $dom -le 31 ]; then
            level=3
        fi
    else
        case $day in
        "Mon") level=6 ;;
        "Tue") level=5 ;;
        "Wed") level=8 ;;
        "Thu") level=7 ;;
        "Fri") level=9 ;;
        "Sat") level=8 ;;
        esac
    fi
elif [ "$backup_mode" == "basic" ] ; then
    # dump is 9 any day but Sunday
    if [[ $day == "Sun" ]]; then
            level=0
    else
            level=9
    fi
else
    echo "ERROR: Unknown backup mode and no level specified"
    exit 1
fi

# dirs to back up - used to be:
# backups=(hda1 hda2 hda5 hda6)
#But now I need to be a bit more sophisticated.
#List filesystems to back up and use mount to find where they are.
backups=()

for fs in "${backup_filesystems[@]}" ; do
    #DEBUG
    #echo "Trying $fs"
    device=`mount | egrep "[^[:space:]]+ on $fs type ext[234]" | awk '{print 
$1}'`

    if [ "$device" != "" ]; then
        backups[${#backups[@]}]=$device
    fi
done

#Did I find anything to backup?
true ${backups:?No partitions found to backup - from paths 
${backup_filesystems[@]}} 

#DEBUG
# echo ${backups[@]} $level $compression_mode
# exit

# if backup drive is already mounted then try to unmount it first.              
# if this is in use the step will fail and exit                                 
/bin/mount | grep -q "/backups" && /bin/umount /backups 2>/dev/null

# mount necessary drive - must be listed
# in /etc/fstab in order to be mounted
/bin/mount "$backup_destination" 2>/dev/null || exit 0

# dump each directory, one at a time
for item in "${backups[@]}"; do
    basename=`basename $item`

    #sync or swim
    sync
    /sbin/dump -"$level" -"$compression_mode" -n -u -f 
"$backup_destination/$basename.bak.$level" "$item"
done

# umount drive
/bin/umount "$backup_destination" 
-- 
ubuntu-uk@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk
https://wiki.ubuntu.com/UKTeam/

Reply via email to