Updated nasbackup.sh
This commit is contained in:
parent
868c1198fe
commit
efe77cbda9
44
nasbackup.sh
44
nasbackup.sh
@ -1,30 +1,48 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#apps backup downloads fun games movies mp3s tvshows wow
|
#apps backup downloads fun games movies mp3s tvshows wow
|
||||||
|
|
||||||
mkdir -p /var/log/nasbackup
|
|
||||||
|
|
||||||
MAILTO=mmckinnon@comprofix.com
|
MAILTO=mmckinnon@comprofix.com
|
||||||
SMTP=mail.comprofix.com
|
SMTP=mail.comprofix.com
|
||||||
|
|
||||||
MAILFROM="$(hostname)@$(dnsdomainname)"
|
MAILFROM="$(hostname)@$(dnsdomainname)"
|
||||||
BODSUBJECT="Backup Log `date +%d-%m-%Y`"
|
SUBJECT="Backup Log `date +%d-%m-%Y`"
|
||||||
LOGFOLDER=/var/log/nasbackup
|
LOGFOLDER=/var/log/nasbackup
|
||||||
|
LOGFILE=$LOGFOLDER/backuplog-`date +%d-%m-%Y.log`
|
||||||
|
THISSERVER=`hostname --fqdn`
|
||||||
N_DAYS=7
|
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
|
DASHES="---------------------------------------------------------------------------------"
|
||||||
echo "****************************************************************" > $LOG 2>&1
|
DASHES2="================================================================================="
|
||||||
echo " Start Backup $(date) " >> $LOG 2>&1
|
|
||||||
echo "****************************************************************" >> $LOG 2>&1
|
|
||||||
|
|
||||||
#rsync -urtlPO --delete --exclude 'kvm' /data/ /media/nas/ >> $LOG 2>&1
|
startlogging
|
||||||
rsync -urtlOv --partial --delete --exclude 'kvm' /data/ /media/nas/ >> $LOG 2>&1
|
|
||||||
|
|
||||||
echo "****************************************************************" >> $LOG 2>&1
|
mkdir -p $LOGFOLDER
|
||||||
echo " Finished Backup $(date) " >> $LOG 2>&1
|
|
||||||
echo "****************************************************************" >> $LOG 2>&1
|
|
||||||
|
|
||||||
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 {} \;
|
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