All pastes #978908 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-04-09 22:15 UTC
rendered paste body
#!/bin/bash
# Title: St0len.co.za backup script
# Author: Allan Clark - <napta2k@gmail.com>
# Date: 9th April 2008 - Version 0.1
# Comment: You're only as good as your last backup!

#
# Variables
BACKUP_DST=/mnt/backup-disk             # Alternative disk (ad6)
BACKUP_SRC=/                            # Backup whole /
GREP=/usr/bin/grep                      # Path to grep(1) binary
MAILTO=backups@st0len.co.za             # E-mail address of backup administrator(s)
MAILX=/usr/bin/mailx                    # Path to mailx(1) binary
MOUNT=/sbin/mount                       # Path to mount(1) binary
RSYNC=/usr/local/bin/rsync              # Path to rsync(1) binary

#
# Function: Check backup-disk is mounted
function chk_backup_disk { 

  $MOUNT | $GREP "$BACKUP_DST"

  if [ $? -eq 1 ]; then
     echo "ERROR: $BACKUP_DST is not mounted. Aborting!"
     exit 1
  fi
}

#
# Function: Rsync data to second disk
function rsync_data {

   echo "`date "+%H:%M:%S"` Starting rsync backup src: $BACKUP_SRC dst: $BACKUP_DST on host: `hostname`"
   echo " "
   $RSYNC -avz --exclude /mnt/backup-disk --delete-after $BACKUP_SRC $BACKUP_DST
   echo " "
   echo "`date "+%H:%M:%S"` Finished rsync backup src: $BACKUP_SRC dst: $BACKUP_DST on host: `hostname`"
}

#
# Main code starts here

#
# Check to see if the backup disk is mounted
chk_backup_disk

#
# Execute rsync
rsync_data | tee $RSYNC_LOG

#
# Mail backup report
cat $RSYNC_LOG | $MAILX -s "Nightly rsync backup report for: `hostname`" $MAILTO