Last active
March 29, 2020 09:04
-
-
Save TechnoSparks/158b5818a9335f43cebc5d5d3ab6b94c to your computer and use it in GitHub Desktop.
Use rsync to do incremental backup, that utilises "--link-dest" instead of "--backup". This allows the benefit of having all the files in a single directory
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 | |
# EXTEND AS NEEDED | |
# Derived from https://www.howtogeek.com/175008/the-non-beginners-guide-to-syncing-data-with-rsync/ | |
# confable | |
# backup_misc_dir needs to be absolute. careful! | |
to_backup="$(pwd)/Moonglow" | |
backup_dir="$(pwd)/Moonglow Backups" | |
backup_misc_dir="$backup_dir/logs and misc" | |
# hardcoded | |
time=$(date +"%Y-%m-%d-%H%M") | |
timeB=$time"-basis" | |
time_latest="$backup_misc_dir/time-latest.txt" | |
time_old="$backup_misc_dir/time-previous.txt" | |
log=$backup_misc_dir/$time.log | |
logB=$backup_misc_dir/$timeB.log | |
# init if new | |
[ ! -d "$backup_dir" ] && mkdir -p "$backup_dir" | |
[ ! -d "$backup_misc_dir" ] && mkdir -p "$backup_misc_dir" | |
if [ ! -f "$time_latest" ]; then | |
echo $timeB > "$time_latest" | |
rsync -ahP --delete --delete-excluded --stats --log-file="$logB" "$to_backup/" "$backup_dir/$timeB/" | |
echo "Init completion" | |
exit # because it is new | |
fi | |
# update time tracker | |
cp -f "$time_latest" "$time_old" # preserve old | |
echo $time > "$time_latest" # generate new | |
#rsync command | |
rsync -ahP --delete --delete-excluded --stats --log-file="$log" --link-dest="$backup_dir/$(cat "$time_old")" "$to_backup/" "$backup_dir/$time/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment