Created
September 14, 2017 20:16
-
-
Save toolboc/0bf1472e004f0a5045a43208641c9761 to your computer and use it in GitHub Desktop.
backup.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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