SimpleDirBackup
From RdiffBackupWiki
A very simple script to backup a directory (in this case, a CVS repository) to another partition in the filesystem. Some parts based on TroelsScript
#!/bin/bash
# simple_backup.sh: a very simple script to backup CVS repository to another partition
# I added this script to cron:
# 35 13 * * * /etc/simple_backup.sh &> /var/log/bkp/`date +%m%d-%H%M`.log
# -------------
# CONFIG
# -------------
TIMESTAMP=`date +%m%d_%H%M`
# Backup Destination is a mounted partition on /backup
DST="/backup/cvs"
# The disk where this partition is located
DISK="/dev/hdb4"
# The directory to backup
SRC="/opt/cvsrepository"
# How long to keep backup history
# In this case, the user can recover the backup state as it was 9 months ago (maxage)
MAXAGE="9M"
# Path to rdiff-backup binary
RDIFF="/usr/bin/rdiff-backup"
# Log file directory - needs to be created
LOG="/var/log/bkp"
# Some basic configuration options; see the manual
OPTIONS="--print-statistics --no-change-dir-inc-perms"
# ---------------
# BACKUP
# ---------------
echo " -- $TIMESTAMP -- "
mount $DISK -o remount,rw
if [ ! -d $DST ]
then
touch $LOG/err.log
echo "$TIMESTAMP Invalid DST, will create... " >> /var/log/bkp/err.log
mkdir $DST
fi
if [ ! -d $SRC ]
then
touch $LOG/err.log
echo "$TIMESTAMP Invalid SRC, aborting... " >> /var/log/bkp/err.log
mount $DISK -o remount,ro
exit 1
fi
echo "Backup: $RDIFF $OPTIONS $SRC $DST"
$RDIFF $OPTIONS $SRC $DST
# It went well, remove stuff older than MAXAGE
if [ $? -eq 0 ]; then
$RDIFF --force --remove-older-than $MAXAGE $DST
else
echo $? > $LOG/fail$TIMESTAMP.log
fi
mount $DISK -o remount,ro
echo "-- EOF --"
See also:
- ContribScripts
