Last active
September 19, 2023 12:31
-
-
Save aquigni/e86042516ff33c33ec564e719b132d19 to your computer and use it in GitHub Desktop.
Rclone syncing bash script
This file contains 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="gdrv_crypt" | |
LOGFILE="/var/log/rclone/rclone_sync.log" | |
LOGLEVEL[1]="DEBUG" | |
LOGLEVEL[2]="INFO" | |
LOGLEVEL[3]="NOTICE" | |
LOGLEVEL[4]="ERROR" | |
LOCALDIR[1]="/boot" | |
LOCALDIR[2]="/etc" | |
LOCALDIR[3]="/home" | |
LOCALDIR[4]="/root" | |
LOCALDIR[5]="/var/lib" | |
LOCALDIR[6]="/var/www/a-u.me" | |
LOCALDIR[7]="/var/www/cloud/conf" | |
LOCALDIR[8]="/var/www/creativearsolutions.com" | |
LOCALDIR[9]="/var/www/kraska-store" | |
PARAM[1]="--log-file=$LOGFILE" | |
PARAM[2]="--log-level=${LOGLEVEL[3]}" | |
PARAM[3]="--copy-links" | |
PARAM[4]="--buffer-size 64" | |
PARAM[5]="--transfers 100" | |
PARAM[6]="--checkers 10" | |
PARAM[7]="--auto-confirm" | |
PARAM[8]="--fast-list" | |
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 | |
rclone sync $FROM $TO ${PARAM[*]} | |
echo $ENDED | tee -a $LOGFILE | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment