Skip to content

Instantly share code, notes, and snippets.

@toolboc
Created September 14, 2017 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toolboc/0bf1472e004f0a5045a43208641c9761 to your computer and use it in GitHub Desktop.
Save toolboc/0bf1472e004f0a5045a43208641c9761 to your computer and use it in GitHub Desktop.
backup.sh
#!/bin/bash
#set -e
BACKUPDIR="/backups"
BACKUPDEV="/dev/sdb1"
DATE=`date +%F`
CLEANDATE=`date +%F -d "1 month ago"`
#see if its mounted
MOUNTSTATUS=`cat /proc/mounts | grep $BACKUPDEV | awk {'print $1'}`
if [[ $MOUNTSTATUS == $BACKUPDEV ]];
then
BACKUP_STATUS=0
else
mount /dev/sdb1 /backups/
if [[ $MOUNTSTATUS == $BACKUPDEV ]];
then
BACKUP_STATUS=0
fi
fi
# error condition... send an email
#if (( $BACKUP_STATUS == 1 )); then
# echo "Backup process failed. Possible cause: $BACKUPDEV not mounted" | mail -s "Backup failure" toolboc@gmail.com
# exit 1
#fi
# no error conditions, proceed with backup
if (( $BACKUP_STATUS == 0 )); then
rm -f $BACKUPDIR/backup-$CLEANDATE.iso
#make the backup
mkisofs -R -iso-level 4 -m '/mnt/*' -m '/proc/*' -m '/sys/*' -m '/dev/*' -m '/backups/*' -V $DATE -o $BACKUPDIR/backup-$DATE.iso /
echo "Backup successfully created on $DATE" | mail -s "Backup created" toolboc@gmail.com
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment