Last active
June 16, 2016 21:51
-
-
Save nhoffman/9ec7f4daabada97cb6558fdc7fe5a2f1 to your computer and use it in GitHub Desktop.
Incremental backup using rsync
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 | |
# Incremental backup using rsync | |
# see http://www.mikerubel.org/computers/rsync_snapshots/#Incremental | |
set -e | |
BACKUP_DIR=backup | |
rot_cycle_days=7 # for example | |
limit=$(($rot_cycle_days-1)) | |
mkdir -p "$BACKUP_DIR.$limit" | |
mv "$BACKUP_DIR.$limit" "$BACKUP_DIR.tmp" | |
for i in $(seq 0 $((limit-1))); do | |
mkdir -p "$BACKUP_DIR.$((limit-i-1))" | |
mv "$BACKUP_DIR.$((limit-i-1))" "$BACKUP_DIR.$((limit-i))" | |
done | |
mv "$BACKUP_DIR.tmp" "$BACKUP_DIR.0" | |
# these cp options not supported on os x | |
cp --archive --link "$BACKUP_DIR.1/." "$BACKUP_DIR.0" | |
rsync -a --delete "$BACKUP_DIR/" "$BACKUP_DIR.0/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment