Commit 1b511dc6 authored by Karl Kornel's avatar Karl Kornel
Browse files

hidpl-red: Create snapshot, and stop syncing xattrs

* We now take a ZFS snapshot after every backup.
* rsync excludes temp directories.
* rsync skips syncing extended attributes.  This is because:
** We can't set the selinux xattr all the time, because CentOS6 and CentOS7 have different contexts and file types.
** We can't use custom xattrs, because ZFS doesn't support them on symlinks.
* The path stored in the variable is now relative (although relative to root).  This is needed for the `zfs snapshot` command.
parent 9c6b1473
Loading
Loading
Loading
Loading
+18 −9
Original line number Diff line number Diff line
SERVER_FQDN='hidpl-red.stanford.edu'
SRC_PATH='/.'
BACKUP_PATH="/archive/zfs01/$(date +%B)/hidpl-red/root"
BACKUP_PATH="archive/hidpl-red/root"
MAIL_TO='akkornel@stanford.edu'

DEBUG=1
@@ -55,21 +55,30 @@ test -d $BACKUP_PATH || mkdir -p $BACKUP_PATH
echo 'Running the backup!'
echo -n 'Backup started on ' >> $LOG_PATH
date >> $LOG_PATH
rsync -aHAX -r -x -v root@$SERVER_FQDN:$SRC_PATH $BACKUP_PATH/. >> $LOG_PATH 2>&1
rsync -aHA -r -x -v --exclude /tmp --exclude /var/tmp root@$SERVER_FQDN:$SRC_PATH /$BACKUP_PATH/. >> $LOG_PATH 2>&1
RSYNC_EXIT_CODE=$?
echo 'Program finished on ' >> $LOG_PATH
date >> $LOG_PATH

# See if the backup worked
if [ $? -eq 0 ]; then
	echo 'Backup complete!'
	[ $MAIL_ON_COMPLETE -eq 1 ] &&
	echo 'Wooo!' | mail -s "Backup for $SERVER_FQDN Complete!" $MAIL_TO

# If the backup had a problem, send a mail about it.
else
if [ $RSYNC_EXIT_CODE -ne 0 ]; then
	echo 'Problem!'
	echo "Log file in $LOG_PATH" | mail -s "Backup problem with $SERVER_FQDN" $MAIL_TO
	echo "Log file from $LOG_PATH attached!" | mail -a $LOG_PATH -s "Backup problem with $SERVER_FQDN" $MAIL_TO
	exit 1
fi

# Take a snapshot of the backed-up directory
[ $DEBUG -eq 1 ] && echo 'Taking ZFS snapshot'
SNAPSHOT_NAME=$(date +%F_%T)
zfs snapshot "${BACKUP_PATH}@${SNAPSHOT_NAME}"
ZFS_EXIT_CODE=$?

# See if the snapshot worked
if [ $ZFS_EXIT_CODE -eq 0 ]; then
	echo 'Backup complete!'
	[ $MAIL_ON_COMPLETE -eq 1 ] &&
	echo "Snapshot is ${BACKUP_PATH}@${SNAPSHOT_NAME}" | mail -s "Backup for $SERVER_FQDN Complete!" $MAIL_TO
fi

# All done!