Rsync
Notes in progress
For backups
Prune script
This is a script that deletes old entries of rsync backup.
#!/bin/bash dir=/srv/rsync-target/ threemonthago=`date -d '-3 month' +"%y-%m-%d"` year=`date -d $threemonthago +%y` month=`date -d $threemonthago +%m` find $dir -name ${year}-${month}-0* -delete fivemonthago=`date -d '-5 month' +"%y-%m-%d"` year=`date -d $fivemonthago +%y` month=`date -d $fivemonthago +%m` find $dir -name ${year}-${month}-2* -delete oneyearago=`date -d '-1 year' +"%y-%m-%d"` year=`date -d $oneyearago +%y` month=`date -d $oneyearago +%m` if [ $month -eq 02 ]; then find $dir -name ${year}-${month}-1* -not -path ${dir}*${year}-${month}-19* -delete else find $dir -name ${year}-${month}-1* -delete find $dir -name ${year}-${month}-31* -delete fi
This crontab command can be used for setting the script to run first sunday of every month:
00 01 * * 0 [ $(date +\%d) -le 07 ] && /path/to/script
Tidying up
Script for tidying up after an outage causes previous backup to fail (start but not complete, leaving the inprogress directory)
NB only use this script if the previous backup failed to complete, but mostly finished, else the next run will copy lots of new data. If the backup failed early in its normal runtime (which you can get an idea of from the log entries, or by using ls -l to see which directories have the right timestamp (as opposed to the timestamp of the failed backup run). If it failed fairly early, it's best to just delete the "inprogress" directory, and if relevant resolve whatever issue caused the backup to fail.
if [ $# -ne 1 ] ; then echo "Error: you need to provide the full path to a directory" exit 1 fi
#!/bin/bash DIRDATE=`/bin/date --date="1 day ago" +"%F"` FIRSTCHAR=${1:0:1} echo $FIRSTCHAR if [ ${FIRSTCHAR} = "/" ] ; then ROOTDIR=$1 else ROOTDIR=/$1 fi if [ -d $ROOTDIR/inprogress ] ; then DESTDIR=${ROOTDIR}/${DIRDATE} if [ -d $DESTDIR ] ; then DIRDATE=`/bin/date +"%F"` DESTDIR=${ROOTDIR}/${DIRDATE} fi /bin/mv ${ROOTDIR}/inprogress ${DESTDIR} /bin/rm ${ROOTDIR}/latest /bin/ln -s ${DESTDIR} ${ROOTDIR}/latest else echo No inprogress directory found at $ROOTDIR fi