Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A rsync backup script
#!/bin/bash
# Source URL: http://www.plone-entwicklerhandbuch.de/plone-entwicklerhandbuch/produktivserver/backup-der-zodb/rsync-backup.sh/view
# SOURCES and TARGET must end with slash
SOURCES="/home/plone/plone41_buildout/backups/backup_*"
SOURCES="${SOURCES} /home/plone/plone41_buildout/var/blobbackup*/*.0/"
TARGET="/backups/plone/plone41_buildout/"
MOUNTPOINT="/backups/"
LOGFILE="/home/plone/plone41_buildout/var/log/backup_plone41.log"
EXPIREDAYS=6
RSYNC="--delete"
SSHUSER="backup"
SSHHOST="backup.veit-schiele.de"
SSHPORT=22
### do not edit ###
/bin/date > $LOGFILE
MOUNTED=$(/bin/mount | /bin/fgrep "$MOUNTPOINT");
if [ -z "$MOUNTPOINT" ] || [ -n "$MOUNTED" ]; then
if [ -e $TARGET ]; then
LASTBACKUP=$(/bin/ls -d $TARGET[[:digit:]]* 2>> $LOGFILE | /usr/bin/sort -r | /usr/bin/head -1)
fi
TODAY=$(/bin/date +%F)
if [ $EXPIREDAYS -gt 0 ]; then
EXPIRED=$(/usr/bin/find $TARGET[[:digit:]]* -maxdepth 0 -ctime +$EXPIREDAYS 2>> $LOGFILE)
for EX in $(/bin/echo $EXPIRED)
do
/bin/echo "rm -rf $EX " >> $LOGFILE
/bin/rm -rf $EX
done
fi
for SOURCE in $(/bin/echo $SOURCES)
do
if [ "$LASTBACKUP" ]; then
INC="--link-dest=$LASTBACKUP$SOURCE"
fi
if [ "$SSHUSER" ] && [ "$SSHHOST" ] && [ "$SSHPORT" ]; then
SSH="ssh -p $SSHPORT -l $SSHUSER";
SOURCEDIR="$SSHHOST:$SOURCE";
else
SOURCEDIR=$SOURCE;
fi
/bin/mkdir -p $TARGET$TODAY$SOURCE >> $LOGFILE
echo "/usr/bin/rsync -e \"$SSH\" --exclude=.* -av $SOURCEDIR $RSYNC $INC $TARGET$TODAY$SOURCE " >> $LOGFILE 2>> $LOGFILE;
/usr/bin/rsync -e "$SSH" -av $SOURCEDIR $RSYNC $INC $TARGET$TODAY$SOURCE >> $LOGFILE 2>> $LOGFILE;
done
else
/bin/echo "$MOUNTPOINT not mounted" >> $LOGFILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.