Created
November 30, 2009 08:56
-
-
Save markuswustenberg/245345 to your computer and use it in GitHub Desktop.
Backup script using hardlinks
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 | |
## Source dirs or files to be copied | |
SRC="/list/of/dirs/space/separated /another/dir" | |
## Exclude-args, let it be empty if nothing is to be excluded | |
EXCLUDE_FROM="--exclude-from=/path/to/exclude/file" | |
## Destination host (including user if necessary, user@host) | |
DEST_HOST="[email protected]" | |
## Destination dir without trailing slash | |
DEST_DIR="backup" | |
## Rsync arguments | |
RSYNC_ARGS="-avz --relative --delete --delete-excluded $EXCLUDE_FROM" | |
## Start of script | |
if [ $# != 2 ]; then | |
echo "Usage: backup.sh interval_name count" | |
exit 1 | |
fi | |
NAME=$1 | |
COUNT=$2 | |
TIMESTAMP=`date -u "+%Y-%m-%d %H:%M:%S%z"` | |
echo "*** Backup started $TIMESTAMP (interval $NAME, count $COUNT) ***" | |
echo "Deleting $DEST_DIR/$NAME.$((COUNT-1))" | |
ssh $DEST_HOST rm -rf $DEST_DIR/$NAME.$(($COUNT-1)) | |
for i in `seq $(($COUNT-1)) -1 2`; | |
do | |
j=$(($i-1)) | |
echo "Moving $DEST_DIR/$NAME.$j to $DEST_DIR/$NAME.$i" | |
ssh $DEST_HOST mv $DEST_DIR/$NAME.$j $DEST_DIR/$NAME.$i | |
done | |
echo "Copying $DEST_DIR/$NAME.0 to $DEST_DIR/$NAME.1" | |
ssh $DEST_HOST cp -al $DEST_DIR/$NAME.0 $DEST_DIR/$NAME.1 | |
echo "Copying source ($SRC) to $DEST_HOST:$DEST_DIR/$NAME.0/" | |
rsync $RSYNC_ARGS $SRC $DEST_HOST:$DEST_DIR/${NAME}.0/ | |
ssh $DEST_HOST touch $DEST_DIR/$NAME.0 | |
TIMESTAMP=`date -u "+%Y-%m-%d %H:%M:%S%z"` | |
echo "*** Backup ended $TIMESTAMP ***" | |
echo "Quota as follows:" | |
ssh $DEST_HOST quota |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment