Advertisement
ghzgod

Borg + RClone

Dec 5th, 2019
7,602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.58 KB | None | 0 0
  1. #!/bin/sh
  2. LOGFILE="/boot/logs/Borg.txt"
  3.  
  4. # Close if rclone/borg running
  5. if pgrep "borg" || pgrep "rclone" > /dev/null
  6. then
  7.     echo "$(date "+%m-%d-%Y %T") : Backup already running, exiting" 2>&1 | tee -a $LOGFILE
  8.     exit
  9.     exit
  10. fi
  11.  
  12. # Close if parity sync started (disabled for now)
  13. #PARITYCHK=$(/root/mdcmd status | egrep STARTED)
  14. #if [[ $PARITYCHK == *"STARTED"* ]]; then
  15. #    echo "Parity check running, exiting"
  16. #    exit
  17. #    exit
  18. #fi
  19.  
  20.  
  21. #This is the location your Borg program will store the backup data to
  22. export BORG_REPO='/YOURREPODESTINATION'
  23.  
  24. #This is the location you want Rclone to send the BORG_REPO to
  25. export CLOUDDEST='GDrive:/YOURRCLONEGDRIVEFOLDERFORBORG'
  26.  
  27. #Speeds up the backup by caching more
  28. #export BORG_FILES_CACHE_TTL=26
  29.  
  30. #Setting this, so you won't be asked for your repository passphrase:
  31. export BORG_PASSPHRASE='YOURREPOKEY'
  32.  
  33. export BORG_CACHE_DIR='/mnt/user/appdata/borg/cache/'
  34. export BORG_BASE_DIR='/mnt/user/appdata/borg/'
  35.  
  36. #Backup my unraid directories into an archive
  37. SECONDS=0
  38.  
  39.  
  40. echo "$(date "+%m-%d-%Y %T") : Borg backup has started" 2>&1 | tee -a $LOGFILE
  41. borg create                         \
  42.     --verbose                       \
  43.     --info                          \
  44.     --list                          \
  45.     --filter AMEx                   \
  46.     --files-cache=mtime,size        \
  47.     --stats                         \
  48.     --show-rc                       \
  49.     --compression lz4               \
  50.     --exclude-caches                \
  51.     --exclude /mnt/user/myfirstexcludeddirectory              \
  52.     --exclude /mnt/user/mysecondexcludedpdirectory             \
  53.     --exclude /mnt/user/mythirdexcludeddirectory              \
  54.     \
  55.     $BORG_REPO::'{hostname}-{now}'  \
  56.     \
  57.     /mnt/user/myfirstbackupdirectory              \
  58.     /mnt/user/mysecondbackupdirectory             \
  59.     /mnt/user/mythirdtbackupdirectory              \
  60.     /mnt/user/myfourthbackupdirectory              \
  61.    
  62.     >> $LOGFILE 2>&1
  63.  
  64.  
  65. backup_exit=$?
  66. # Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
  67. # archives of THIS machine. The '{hostname}-' prefix is very important to
  68. # limit prune's operation to this machine's archives and not apply to
  69. # other machines' archives also:
  70. #echo "$(date "+%m-%d-%Y %T") : Borg pruning has started" 2>&1 | tee -a $LOGFILE
  71. borg prune                          \
  72.     --list                          \
  73.     --prefix '{hostname}-'          \
  74.     --show-rc                       \
  75.     --keep-daily    7               \
  76.     --keep-weekly   4               \
  77.     --keep-monthly  6               \
  78.     >> $LOGFILE 2>&1
  79.  
  80. prune_exit=$?
  81. #echo "$(date "+%m-%d-%Y %T") : Borg pruning has completed" 2>&1 | tee -a $LOGFILE
  82.  
  83. # use highest exit code as global exit code
  84. global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
  85.  
  86. # Execute if no errors
  87. if [ ${global_exit} -eq 0 ];
  88. then
  89.     borgstart=$SECONDS
  90.     echo "$(date "+%m-%d-%Y %T") : Borg backup completed in  $(($borgstart/ 3600))h:$(($borgstart% 3600/60))m:$(($borgstart% 60))s" | tee -a >> $LOGFILE 2>&1
  91.  
  92. #Reset timer
  93.     SECONDS=0
  94.     echo "$(date "+%m-%d-%Y %T") : Rclone Borg sync has started" >> $LOGFILE
  95.     rclone sync $BORG_REPO $CLOUDDEST -P --stats 1s -v 2>&1 | tee -a $LOGFILE
  96.     rclonestart=$SECONDS  
  97.     echo "$(date "+%m-%d-%Y %T") : Rclone Borg sync completed in  $(($rclonestart/ 3600))h:$(($rclonestart% 3600/60))m:$(($rclonestart% 60))s" 2>&1 | tee -a $LOGFILE
  98. # All other errors
  99. else
  100.     echo "$(date "+%m-%d-%Y %T") : Borg has errors code:" $global_exit 2>&1 | tee -a $LOGFILE
  101. fi
  102. exit ${global_exit}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement