「shellの学習」SVN(Subversion)リポジトリのバックアップ方法
スクリプトコード:
#!/bin/bash
SVN_REPOS=(/www/svn/web/*.arkgame.com)
BACKUP_BASE_DIR=/www/repo_backup
backup_rotate() {
if cd $1
then
for num in 7 6 5 4 3 2 1
do
old=`expr $num + 1`
if [ -d backup.${num} ]
then
if [ -d backup.${old} ]
then
rm -rf backup.${old} && mv backup.${num} backup.${old}
else
mv backup.${num} backup.${old}
fi
fi
done
else
echo “change BACKUP_DIR error!"
exit 1
fi
}
for REPO in “${SVN_REPOS[@]}"
do
REPONAME=`/usr/bin/basename $REPO`
BACKUP_DIR="$BACKUP_BASE_DIR/$REPONAME"
[ -d “$BACKUP_DIR" ] || mkdir -p $BACKUP_DIR
cd $BACKUP_DIR && backup_rotate $BACKUP_DIR
/usr/bin/svnadmin hotcopy $REPO $BACKUP_DIR/backup.1
done
説明:
7個バックアップ、backup.1最新バックアップ、backup.7古いバックアップ