Skip to content

Instantly share code, notes, and snippets.

@cofemei
Created September 29, 2014 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cofemei/293ddcc279051c1585d5 to your computer and use it in GitHub Desktop.
Save cofemei/293ddcc279051c1585d5 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