-
-
Save orisdorch/0f6dbfd884ac018073d27053bc25b417 to your computer and use it in GitHub Desktop.
Rclone syncing bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############################################################## | |
### RCLONE SYNC SCRIPT | |
############################################################## | |
### crontab -e every 4 hours: | |
# 0 */4 * * * root /root/scrpts/rclone_sync.sh >/dev/null 2>&1 | |
### Useful rclone commands: | |
# rclone config show | |
# rclone genautocomplete $SHELL | |
# rclone ncdu $REMOTEDIR: | |
# rclone tree -aC --dirsfirst --human $REMOTEDIR: | |
### Check if sync operation is still in progress: | |
if pidof -o %PPID -x "rclone_sync.sh"; then | |
exit 1 | |
fi | |
### Defining variables: | |
REMOTEDIR="/mnt/disks/UNRAID_EXT_BACKUP/rclone" | |
LOGFILE="/var/log/rclone/rclone_sync.log" | |
LOGLEVEL[1]="DEBUG" | |
LOGLEVEL[2]="INFO" | |
LOGLEVEL[3]="NOTICE" | |
LOGLEVEL[4]="ERROR" | |
LOCALDIR[1]="/mnt/cache" | |
LOCALDIR[2]="/mnt/disk1" | |
LOCALDIR[3]="/mnt/disks/XFS/appdatabackup" | |
PARAM[1]="--log-file=$LOGFILE" | |
PARAM[2]="--log-level=${LOGLEVEL[3]}" | |
PARAM[3]="--buffer-size 64" | |
PARAM[4]="--transfers 100" | |
PARAM[5]="--checkers 10" | |
PARAM[6]="--auto-confirm" | |
PARAM[7]="--fast-list" | |
PARAM[8]="--backup-dir $REMOTEDIR/_delete" | |
#PARAM[3]="--copy-links" | |
STARTED="$(date "+%d.%m.%Y %T") RCLONE SYNC OPERATION STARTED" | |
ENDED="$(date "+%d.%m.%Y %T") RCLONE SYNC OPERATION ENDED" | |
### Executing main script | |
for FROM in ${LOCALDIR[*]}; do | |
TO=$REMOTEDIR$FROM | |
echo $STARTED | tee -a $LOGFILE | |
echo "rclone sync $FROM $TO ${PARAM[*]}" | tee -a $LOGFILE | |
rclone sync $FROM $TO ${PARAM[*]} | |
echo $ENDED | tee -a $LOGFILE | |
done | |
exit 0 |
Author
orisdorch
commented
Jan 8, 2022
- revised to accommodate a local destination [ TO=$REMOTEDIR:$FROM ---> TO=$REMOTEDIR$FROM]
- added --backup-dir for a 'trash' folder of items to be purged from the remote device (for manual review and purge)
- added logging of the backup command [echo "rclone sync $FROM
$TO $ {PARAM[*]}" | tee -a $LOGFILE]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment