Last active
May 27, 2023 07:00
-
-
Save DNI9/f8bcefb1acc6869b48eb2577557f24fc to your computer and use it in GitHub Desktop.
a simple backup script using rclone, can be run with anacron daily
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add to
/etc/anacrontab
1 5 conf_backup ~/Documents/conf/simple-backup.sh