getRemoteBackup.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. #TODO:
  3. if pidof -o %PPID -x "$0" > /dev/null; then
  4. echo "Backup job already running. Exiting..."
  5. exit
  6. fi
  7. logFilePath=/home/sebastian/ARCHIVE/sebastian/3000_BACKUP/sebastianvendt.de.log
  8. tmpLogFilePath=/tmp/tmp_backup.log
  9. retryAttempts=1
  10. touch $tmpLogFilePath
  11. while [ "$retryAttempts" -ge "0" ]
  12. do
  13. date >> $tmpLogFilePath
  14. echo "Starting backup job" >> $tmpLogFilePath
  15. 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
  16. rsyncExitCode=$?
  17. echo "Ending backup job" >> $tmpLogFilePath
  18. date >> $tmpLogFilePath
  19. echo "" >> $tmpLogFilePath
  20. if [ $rsyncExitCode -eq 0 ]; then
  21. break
  22. fi
  23. retryAttempts=$((retryAttempts-1))
  24. done
  25. #copy over
  26. cat $tmpLogFilePath >> $logFilePath
  27. if [ $rsyncExitCode -eq 0 ]; then
  28. #send mail for success
  29. echo -e "To:mail@sebastianvendt.de\nFrom:Sebastian@manaslu.home\nSubject:Backup SUCCESSFUL on $(date +'%c')\n\n$(cat $tmpLogFilePath)" | sendmail mail@sebastianvendt.de
  30. else
  31. #send mail for failure
  32. echo -e "To:mail@sebastianvendt.de\nFrom:Sebastian@manaslu.home\nSubject:Backup FAILED on $(date +'%c')\n\n$(cat $tmpLogFilePath)" | sendmail mail@sebastianvendt.de
  33. fi
  34. #delete file
  35. rm $tmpLogFilePath