Created
June 8, 2013 16:23
-
-
Save holly/5735713 to your computer and use it in GitHub Desktop.
rsync --link-dest
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 | |
set -e | |
TARGET_DIR=/path/to/target | |
BACKUP_DIR=/path/to/backup | |
RSYNC=/usr/bin/rsync | |
RSYNC_ARGS="-avS --stats --human-readable --delete $CMD_ARGS" | |
ROTATE=3 | |
today=$(date +%Y%m%d) | |
yesterday=$(date +%Y%m%d --date="1 days ago") | |
oldday=$(date +%Y%m%d --date="$ROTATE days ago") | |
rsync_args=$RSYNC_ARGS | |
if [ ! -z "$RSYNC_EXCLUDE_FILE" -a -e "$RSYNC_EXCLUDE_FILE" ]; then | |
rsync_args="$rsync_args --exclude-from=$RSYNC_EXCLUDE_FILE" | |
fi | |
if [ -d "$BACKUP_DIR.$yesterday" ]; then | |
rsync_args="$rsync_args --link-dest=../$(dirname $BACKUP_DIR.$yesterday)" | |
fi | |
if [ ! -d "$BACKUP_DIR.$today" ]; then | |
mkdir "$BACKUP_DIR.$today" | |
ln -s "$BACKUP_DIR.$today" $BACKUP_DIR | |
fi | |
# rotate | |
if [ -d "$BACKUP_DIR.$oldday" ]; then | |
rm -fr "$BACKUP_DIR.$oldday" | |
fi | |
eval $(echo $RSYNC $rsync_args $TARGET_DIR/ $BACKUP_DIR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment