|
@@ -0,0 +1,43 @@
|
|
|
+#!/bin/bash
|
|
|
+
|
|
|
+#TODO:
|
|
|
+
|
|
|
+if pidof -o %PPID -x "$0" > /dev/null; then
|
|
|
+ echo "Backup job already running. Exiting..."
|
|
|
+ exit
|
|
|
+fi
|
|
|
+
|
|
|
+logFilePath=/home/sebastian/ARCHIVE/sebastian/3000_BACKUP/sebastianvendt.de.log
|
|
|
+tmpLogFilePath=/tmp/tmp_backup.log
|
|
|
+retryAttempts=1
|
|
|
+touch $tmpLogFilePath
|
|
|
+
|
|
|
+while [ "$retryAttempts" -ge "0" ]
|
|
|
+do
|
|
|
+ date >> $tmpLogFilePath
|
|
|
+ echo "Starting backup job" >> $tmpLogFilePath
|
|
|
+ rsync --delete --out-format="%t %f %''b" -avze 'ssh -p 9753 -i /home/sebastian/sshKeys/rsyncOnSebastianvendt.de.pem' rsync@sebastianvendt.de:/var/lib/psa/dumps/domains/sebastianvendt.de/ /home/sebastian/ARCHIVE/sebastian/3000_BACKUP/sebastianvendt.de | tee -a $tmpLogFilePath 2>&1
|
|
|
+ rsyncExitCode=$?
|
|
|
+ echo "Ending backup job" >> $tmpLogFilePath
|
|
|
+ date >> $tmpLogFilePath
|
|
|
+ echo "" >> $tmpLogFilePath
|
|
|
+
|
|
|
+ if [ $rsyncExitCode -eq 0 ]; then
|
|
|
+ break
|
|
|
+ fi
|
|
|
+ retryAttempts=$((retryAttempts-1))
|
|
|
+done
|
|
|
+
|
|
|
+#copy over
|
|
|
+cat $tmpLogFilePath >> $logFilePath
|
|
|
+
|
|
|
+if [ $rsyncExitCode -eq 0 ]; then
|
|
|
+#send mail for success
|
|
|
+ echo -e "To:mail@sebastianvendt.de\nFrom:Sebastian@manaslu.home\nSubject:Backup SUCCESSFUL on $(date +'%c')\n\n$(cat $tmpLogFilePath)" | sendmail mail@sebastianvendt.de
|
|
|
+else
|
|
|
+#send mail for failure
|
|
|
+ echo -e "To:mail@sebastianvendt.de\nFrom:Sebastian@manaslu.home\nSubject:Backup FAILED on $(date +'%c')\n\n$(cat $tmpLogFilePath)" | sendmail mail@sebastianvendt.de
|
|
|
+fi
|
|
|
+
|
|
|
+#delete file
|
|
|
+rm $tmpLogFilePath
|