Skip to content

Instantly share code, notes, and snippets.

@DNI9
Last active May 27, 2023 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DNI9/f8bcefb1acc6869b48eb2577557f24fc to your computer and use it in GitHub Desktop.
Save DNI9/f8bcefb1acc6869b48eb2577557f24fc to your computer and use it in GitHub Desktop.
a simple backup script using rclone, can be run with anacron daily
#!/bin/bash
BACKUP_DIR="$HOME/Documents/conf/data/"
LOG_DIR="$HOME/Documents/conf"
LOG_FILE="backup-conf.log"
function handleLog() {
if [ $1 -eq 0 ]; then
echo "$(date +"%Y-%m-%d %H:%M:%S") => SUCCESS: $3 backup successful" | tee -a "$LOG_DIR/$LOG_FILE"
else
echo "$(date +"%Y-%m-%d %H:%M:%S") => FAIL: $2" | tee -a "$LOG_DIR/$LOG_FILE"
fi
}
remotes=("indra:Files/conf" "dropbox:/conf")
for remote in "${remotes[@]}"; do
out=$(rclone copy $BACKUP_DIR "$remote" 2>&1)
handleLog $? "$out" "$remote"
done
# Check log file size and delete if it exceeds 1 MB
log_file_size=$(du -k "$LOG_FILE" | cut -f1)
if [[ $log_file_size -gt 1024 ]]; then
rm "$LOG_FILE"
fi
@DNI9
Copy link
Author

DNI9 commented May 27, 2023

add to /etc/anacrontab

1   5   conf_backup ~/Documents/conf/simple-backup.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment