Guest User

Borg + RClone V2

a guest
Jan 22nd, 2019
1,581
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. LOGFILE="/boot/logs/BORGLOGNAME.txt"
  3.  
  4. # Close if borg running
  5. if pidof -x borg >/dev/null; then
  6. echo "$(date "+%m-%d-%Y %T") : Borg already running, exiting" >> $LOGFILE 2>&1
  7. exit
  8. exit
  9. fi
  10. # Close if rclone running
  11. if pidof -x rclone >/dev/null; then
  12. echo "$(date "+%m-%d-%Y %T") : RClone already running, exiting" >> $LOGFILE 2>&1
  13. exit
  14. exit
  15. fi
  16.  
  17. #This is the location your Borg program will store the backup data to
  18. export BORG_REPO='/mnt/user/Backups/BORGREPONAME'
  19.  
  20. #This is the location you want Rclone to send the BORG_REPO to
  21. export CLOUDDEST='GSuite:/Backup/BORGREPONAME'
  22.  
  23. #Speeds up the backup by caching more
  24. export BORG_FILES_CACHE_TTL=20
  25.  
  26. # Setting this, so you won't be asked for your repository passphrase:
  27. export BORG_PASSPHRASE='MYBORGPASSWORD'
  28.  
  29. # or this to ask an external program to supply the passphrase:
  30. # export BORG_PASSCOMMAND='MYBORGPASSWORD'
  31.  
  32. # Backup the most important directories into an archive named after
  33. # the machine this script is currently running on:
  34.  
  35. borgstart=$(date +'%s')
  36. echo "$(date "+%m-%d-%Y %T") : Borg backup has started" >> $LOGFILE 2>&1
  37. borg create \
  38. --verbose \
  39. --filter AME \
  40. --list \
  41. --stats \
  42. --show-rc \
  43. --compression lz4 \
  44. --exclude /mnt/user/ExcludedFolder1 \
  45. --exclude /mnt/user/ExcludedFolder2 \
  46. \
  47. $BORG_REPO::'{hostname}-{now}' \
  48. /mnt/user/BackupDirectoryName1 \
  49. /mnt/user/BackupDirectoryName2 \
  50. > $LOGFILE \
  51.  
  52.  
  53. backup_exit=$?
  54. # Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
  55. # archives of THIS machine. The '{hostname}-' prefix is very important to
  56. # limit prune's operation to this machine's archives and not apply to
  57. # other machines' archives also:
  58. echo "$(date "+%m-%d-%Y %T") : Borg pruning has started" >> $LOGFILE 2>&1
  59. borg prune \
  60. --list \
  61. --prefix '{hostname}-' \
  62. --show-rc \
  63. --keep-daily 7 \
  64. --keep-weekly 4 \
  65. --keep-monthly 6 \
  66. >> $LOGFILE 2>> $LOGFILE \
  67.  
  68. prune_exit=$?
  69. echo "$(date "+%m-%d-%Y %T") : Borg pruning has completed" >> $LOGFILE 2>&1
  70.  
  71. # use highest exit code as global exit code
  72. global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
  73.  
  74.  
  75. if [ ${global_exit} -eq 0 ];
  76. then
  77. echo "$(date "+%m-%d-%Y %T") : Borg backup completed in $(($(date +'%s') - $borgstart)) seconds" >> $LOGFILE 2>&1
  78. /usr/local/emhttp/webGui/scripts/notify -s "Borg (Local) Backup Completed" -d "Borg (Local) backup completed in $(($(date +'%s') - $borgstart)) seconds"
  79.  
  80. rclonestart=$(date +'%s')
  81. echo "$(date "+%m-%d-%Y %T") : RClone sync has started" >> $LOGFILE 2>&1
  82. rclone sync $BORG_REPO $CLOUDDEST -P --stats 10s -v > $LOGFILE
  83. echo "$(date "+%m-%d-%Y %T") : RClone backup completed in $(($(date +'%s') - $rclonestart)) seconds" >> $LOGFILE 2>&1
  84. /usr/local/emhttp/webGui/scripts/notify -s "Borg (Cloud) Backup Completed" -d "Borg (Cloud) backup completed in $(($(date +'%s') - $rclonestart)) seconds"
  85. fi
  86.  
  87. if [ ${global_exit} -gt 0 ];
  88. then
  89. echo "$(date "+%m-%d-%Y %T") : Borg has errors code:" $global_exit >> $LOGFILE 2>&1
  90. /usr/local/emhttp/webGui/scripts/notify -s "Borg Backup Failed!" -d "Borg Backup Failed with code:" $global_exit
  91. fi
  92.  
  93.  
  94.  
  95.  
  96. exit ${global_exit}
RAW Paste Data