Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- LOGFILE="/boot/logs/BORGLOGNAME.txt"
- # Close if borg running
- if pidof -x borg >/dev/null; then
- echo "$(date "+%m-%d-%Y %T") : Borg already running, exiting" >> $LOGFILE 2>&1
- exit
- exit
- fi
- # Close if rclone running
- if pidof -x rclone >/dev/null; then
- echo "$(date "+%m-%d-%Y %T") : RClone already running, exiting" >> $LOGFILE 2>&1
- exit
- exit
- fi
- #This is the location your Borg program will store the backup data to
- export BORG_REPO='/mnt/user/Backups/BORGREPONAME'
- #This is the location you want Rclone to send the BORG_REPO to
- export CLOUDDEST='GSuite:/Backup/BORGREPONAME'
- #Speeds up the backup by caching more
- export BORG_FILES_CACHE_TTL=20
- # Setting this, so you won't be asked for your repository passphrase:
- export BORG_PASSPHRASE='MYBORGPASSWORD'
- # or this to ask an external program to supply the passphrase:
- # export BORG_PASSCOMMAND='MYBORGPASSWORD'
- # Backup the most important directories into an archive named after
- # the machine this script is currently running on:
- borgstart=$(date +'%s')
- echo "$(date "+%m-%d-%Y %T") : Borg backup has started" >> $LOGFILE 2>&1
- borg create \
- --verbose \
- --filter AME \
- --list \
- --stats \
- --show-rc \
- --compression lz4 \
- --exclude /mnt/user/ExcludedFolder1 \
- --exclude /mnt/user/ExcludedFolder2 \
- \
- $BORG_REPO::'{hostname}-{now}' \
- /mnt/user/BackupDirectoryName1 \
- /mnt/user/BackupDirectoryName2 \
- > $LOGFILE \
- backup_exit=$?
- # Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
- # archives of THIS machine. The '{hostname}-' prefix is very important to
- # limit prune's operation to this machine's archives and not apply to
- # other machines' archives also:
- echo "$(date "+%m-%d-%Y %T") : Borg pruning has started" >> $LOGFILE 2>&1
- borg prune \
- --list \
- --prefix '{hostname}-' \
- --show-rc \
- --keep-daily 7 \
- --keep-weekly 4 \
- --keep-monthly 6 \
- >> $LOGFILE 2>> $LOGFILE \
- prune_exit=$?
- echo "$(date "+%m-%d-%Y %T") : Borg pruning has completed" >> $LOGFILE 2>&1
- # use highest exit code as global exit code
- global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
- if [ ${global_exit} -eq 0 ];
- then
- echo "$(date "+%m-%d-%Y %T") : Borg backup completed in $(($(date +'%s') - $borgstart)) seconds" >> $LOGFILE 2>&1
- /usr/local/emhttp/webGui/scripts/notify -s "Borg (Local) Backup Completed" -d "Borg (Local) backup completed in $(($(date +'%s') - $borgstart)) seconds"
- rclonestart=$(date +'%s')
- echo "$(date "+%m-%d-%Y %T") : RClone sync has started" >> $LOGFILE 2>&1
- rclone sync $BORG_REPO $CLOUDDEST -P --stats 10s -v > $LOGFILE
- echo "$(date "+%m-%d-%Y %T") : RClone backup completed in $(($(date +'%s') - $rclonestart)) seconds" >> $LOGFILE 2>&1
- /usr/local/emhttp/webGui/scripts/notify -s "Borg (Cloud) Backup Completed" -d "Borg (Cloud) backup completed in $(($(date +'%s') - $rclonestart)) seconds"
- fi
- if [ ${global_exit} -gt 0 ];
- then
- echo "$(date "+%m-%d-%Y %T") : Borg has errors code:" $global_exit >> $LOGFILE 2>&1
- /usr/local/emhttp/webGui/scripts/notify -s "Borg Backup Failed!" -d "Borg Backup Failed with code:" $global_exit
- fi
- exit ${global_exit}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement