Updated nasbackup.sh
This commit is contained in:
parent
868c1198fe
commit
efe77cbda9
44
nasbackup.sh
44
nasbackup.sh
@ -1,30 +1,48 @@
|
||||
#!/bin/bash
|
||||
#apps backup downloads fun games movies mp3s tvshows wow
|
||||
|
||||
mkdir -p /var/log/nasbackup
|
||||
|
||||
MAILTO=mmckinnon@comprofix.com
|
||||
SMTP=mail.comprofix.com
|
||||
|
||||
MAILFROM="$(hostname)@$(dnsdomainname)"
|
||||
BODSUBJECT="Backup Log `date +%d-%m-%Y`"
|
||||
SUBJECT="Backup Log `date +%d-%m-%Y`"
|
||||
LOGFOLDER=/var/log/nasbackup
|
||||
LOGFILE=$LOGFOLDER/backuplog-`date +%d-%m-%Y.log`
|
||||
THISSERVER=`hostname --fqdn`
|
||||
N_DAYS=7
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
LOG=$LOGFOLDER/backuplog-`date +%d-%m-%Y`.log
|
||||
echo "****************************************************************" > $LOG 2>&1
|
||||
echo " Start Backup $(date) " >> $LOG 2>&1
|
||||
echo "****************************************************************" >> $LOG 2>&1
|
||||
DASHES="---------------------------------------------------------------------------------"
|
||||
DASHES2="================================================================================="
|
||||
|
||||
#rsync -urtlPO --delete --exclude 'kvm' /data/ /media/nas/ >> $LOG 2>&1
|
||||
rsync -urtlOv --partial --delete --exclude 'kvm' /data/ /media/nas/ >> $LOG 2>&1
|
||||
startlogging
|
||||
|
||||
echo "****************************************************************" >> $LOG 2>&1
|
||||
echo " Finished Backup $(date) " >> $LOG 2>&1
|
||||
echo "****************************************************************" >> $LOG 2>&1
|
||||
mkdir -p $LOGFOLDER
|
||||
|
||||
sendemail -o tls=no -f "NAS BACKUP <$MAILFROM>" -t $MAILTO -u "$BODSUBJECT" -m "$BODSUBJECT" -a $LOG -s $SMTP >> $LOG 2>&1
|
||||
rsync -urtlOv --partial --delete --exclude 'kvm' /data/ /media/nas/ >> $LOGFILE
|
||||
|
||||
FILES=$(find $LOGFOLDER -type f -mtime +$N_DAYS -name '*.log' | wc -l)
|
||||
|
||||
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
|
||||
|
||||
echo "$(date) [MESSAGE] Backup completed $LOGFILE has been emailed." >> $LOGFILE
|
||||
|
||||
stoplogging
|
||||
|
||||
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat $LOGFILE)"
|
||||
|
Loading…
Reference in New Issue
Block a user