Created
October 28, 2018 14:26
-
-
Save DarkPark/7ee7a1d82d57f6a7c23bf46c4f7dd0f7 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# creates daily backups using hard links | |
# should be run on a storage server to backup remote 10.0.0.10 host: | |
# ./backup.sh 10.0.0.10 | |
# can be executed by crontab on a hourly basis | |
# stops execution on any error | |
set -e | |
storage=/root/backups | |
host=$1 | |
date=`date +"%Y.%m.%d"` | |
pathHead="$storage/$host/head" | |
pathDate="$storage/$host/$date" | |
bwlimit=8192 | |
# there should be parameters | |
if [ $# -eq 0 ]; then | |
echo "no arguments supplied" | |
exit 1 | |
fi | |
# make sure main directory is present | |
mkdir -p "$pathHead" | |
# make sure exclude list is present | |
touch "$storage/$host/exclude.list" | |
# check if data for today is present | |
if [ ! -d "$pathDate" ]; then | |
rsync --archive --acls --xattrs --bwlimit=$bwlimit --delete --exclude-from="$storage/$host/exclude.list" --log-file="$pathHead/rsync.log" root@$host:/etc root@$host:/home "$pathHead" && | |
cp --archive --link "$pathHead" "$pathDate" && | |
rm "$pathHead/rsync.log" && | |
/root/scripts/telegram.sh "$host: backup is successful" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment