Last active
March 5, 2018 08:12
-
-
Save serverok/42168e653e1b10a2dac19941878db4b7 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
#!/bin/bash | |
date=`date "+%Y-%m-%dT%H-%M-%S"` | |
backup=/share/MD0_DATA/backup1 | |
targets="/bin /etc /lib /lib64 /opt /sbin /usr /var" | |
if [ -d $backup/logs ]; then | |
mkdir -p $backup/logs | |
fi | |
if [ -d $backup/latest ]; then | |
mkdir -p $backup/latest | |
fi | |
rsync -a --stats --partial -hHAXxuR --log-file=$backup/logs/$date.log $targets --link-dest=$backup/latest $backup/incomplete_$date | |
if [ $? -eq 0 ]; then | |
mv $backup/incomplete_$date $backup/$date && \ | |
rm -f $backup/latest && \ | |
ln -s $backup/$date $backup/latest | |
fi | |
# Delete backups older than 365 days | |
find $backup -maxdepth 1 -type d -mtime +365 -exec rm -rf {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment