serverscripts/nasbackup

52 lines
1.3 KiB
Plaintext
Raw Normal View History

2014-11-20 23:45:20 +10:00
#!/bin/bash
2016-03-27 00:13:51 +10:00
MAILTO="support@comprofix.com"
MAILFROM="support@comprofix.com"
THISSERVER=$(hostname -f)
SMTP="mail.comprofix.com"
2016-04-23 16:44:02 +10:00
SUBJECT="Backup Log `date +%d-%m-%Y`"
2014-11-21 00:56:04 +10:00
LOGFOLDER=/var/log/nasbackup
2016-04-23 16:44:02 +10:00
LOGFILE=$LOGFOLDER/backuplog-`date +%d-%m-%Y.log`
THISSERVER=`hostname --fqdn`
2014-11-21 00:56:04 +10:00
N_DAYS=7
2016-04-23 16:44:02 +10:00
startlogging() {
echo $DASHES2 >> $LOGFILE
echo "$0 started running at $(date)" >> $LOGFILE
echo $DASHES2 >> $LOGFILE
}
stoplogging() {
echo "$(date) [MESSAGE] $0 finished runnning" >> $LOGFILE
echo $DASHES >> $LOGFILE
}
DASHES="---------------------------------------------------------------------------------"
DASHES2="================================================================================="
startlogging
mkdir -p $LOGFOLDER
2014-11-20 23:45:20 +10:00
2016-04-23 16:44:02 +10:00
rsync -urtlOv --partial --delete --exclude 'kvm' /data/ /media/nas/ >> $LOGFILE
2014-11-20 23:45:20 +10:00
2016-04-23 16:44:02 +10:00
FILES=$(find $LOGFOLDER -type f -mtime +$N_DAYS -name '*.log' | wc -l)
2014-11-20 23:45:20 +10:00
2016-04-23 16:44:02 +10:00
if [ $FILES -eq 0 ];
then
echo "$(date) [MESSAGE] No Old Log Files Found" >> $LOGFILE
else
echo "$(date) [MESSAGE] Older than $N_DAYS days will be deleted" >> $LOGFILE
find $LOGFOLDER/* -mtime +$N_DAYS -exec rm {} \;
fi
2016-04-23 16:44:02 +10:00
echo "$(date) [MESSAGE] Backup completed $LOGFILE has been emailed." >> $LOGFILE
2014-11-20 23:45:20 +10:00
2016-04-23 16:44:02 +10:00
stoplogging
2014-11-21 00:56:04 +10:00
2017-06-15 21:59:46 +10:00
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -a "$LOGFILE" -m "$SUBJECT" -q