Created
December 15, 2015 07:47
-
-
Save petrosagg/b23cae56de981f51ca12 to your computer and use it in GitHub Desktop.
simple rsync backup
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 | |
set -o errexit | |
NAME=home | |
SOURCE=/home | |
PATHTOBACKUP=/root/backup | |
date=$(date "+%Y-%m-%dT%H:%M:%S") | |
rm -rf $PATHTOBACKUP/.tmp-$NAME | |
# --link-dest checks if the file exists in the previous backup | |
# and if yes, it creates a hard link | |
rsync \ | |
--archive \ | |
--verbose \ | |
--one-file-system \ | |
--log-file=$PATHTOBACKUP/.tmp-$NAME.log \ | |
--link-dest=$PATHTOBACKUP/$NAME-current \ | |
$SOURCE $PATHTOBACKUP/.tmp-$NAME | |
mv $PATHTOBACKUP/.tmp-$NAME.log $PATHTOBACKUP/$NAME-$date.log | |
mv $PATHTOBACKUP/.tmp-$NAME $PATHTOBACKUP/$NAME-$date | |
ln --symbolic --force --no-dereference $NAME-$date $PATHTOBACKUP/$NAME-current |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment