-
-
Save kimthostrup/0cdd8bfa3ecb0e6fa88a4d56fab2b859 to your computer and use it in GitHub Desktop.
rsync backup 7 day
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-%d` | |
RETENTION_PERIOD="7" | |
HEADER="Backup data" | |
remove_oldfiles(){ | |
echo "Removing directory $1 files older than $RETENTION_PERIOD days" | wall | |
find $1 -type f -mtime +$2 -exec rm '{}' \; | |
} | |
BACKUPDIR="/disk0/svn_backup/001/" | |
back_www_dir="/disk0/svn_backup/" | |
# | |
# 開始備份 | |
# | |
cd $back_www_dir | |
for TARGET in $BACKUPDIR | |
do | |
echo "rsync svn on /disk0/svn_backup/001/" | wall | |
rsync -av -e ssh username@hosename:/var/www/svn /disk0/svn_backup/001/ | |
echo "System backup on $TARGET" | wall | |
BASENAME=`basename $TARGET` | |
tar -zcvf ${BASENAME}-${date}.tar.gz $TARGET 1>/dev/null | |
sleep 2 | |
done | |
# | |
# 刪除7天前的資料 | |
# | |
remove_oldfiles $back_www_dir $RETENTION_PERIOD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment