Skip to content

Instantly share code, notes, and snippets.

@serverok
Last active March 5, 2018 08:12
Show Gist options
  • Save serverok/42168e653e1b10a2dac19941878db4b7 to your computer and use it in GitHub Desktop.
Save serverok/42168e653e1b10a2dac19941878db4b7 to your computer and use it in GitHub Desktop.
#!/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