Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimthostrup/0cdd8bfa3ecb0e6fa88a4d56fab2b859 to your computer and use it in GitHub Desktop.
Save kimthostrup/0cdd8bfa3ecb0e6fa88a4d56fab2b859 to your computer and use it in GitHub Desktop.
rsync backup 7 day
#!/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