问题的第一部分是如何对 SVN 存储库进行增量备份?执行此操作的命令是什么......以及如何自动执行此操作(OS + UNIX)
答案1
如果您想自己动手,请查看“svnlook youngest”和“svnadmin dump --incremental -r${STARTREV}:${ENDREV}”命令。
我已将用于对 SVN 存储库进行完整和增量转储的脚本粘贴在下面,它们将上次备份的修订和日期存储在 /home/svn/var 的子目录中。首先进行完整转储,然后进行任意数量的增量转储。
完整的 SVN 转储脚本:
#!/bin/sh
# Full dump of all subversion repositories
# make sure to get the subversion environment variables
. /etc/profile.d/subversion.sh
# path to subversion binaries
SVN_BINPATH=${SVN_HOME}/bin
# path to parent of all repositories to be dumped
SVN_REPPATH=/opt/svn/repositories
# destination directory for backup files
DUMP_DIR=/backup/svn
# status directory
SVN_VAR=/home/svn/var
DATETIME=`date +%Y%m%d`
for rep in ${SVN_REPPATH}/*;
do
TSTAMP=`date +%s`
CURR_REV=`${SVN_BINPATH}/svnlook youngest ${rep}`
REP_BASE=`basename $rep`
echo "**********************************************************"
echo "`date --rfc-2822` - Full back up - ${rep} : "
echo " current revision ${CURR_REV}"
echo
DUMPFILE=${DUMP_DIR}/${REP_BASE}-${DATETIME}.dmp
${SVN_BINPATH}/svnadmin --quiet dump $rep > ${DUMPFILE}
echo ${TSTAMP} > ${SVN_VAR}/status/dates/${REP_BASE}.dt
echo ${CURR_REV} > ${SVN_VAR}/status/revisions/${REP_BASE}.rev
bzip2 --compress --best ${DUMPFILE}
done
echo
echo `ls -hl ${DUMP_DIR}/*.bz2`
增量 SVN 转储脚本:
#!/bin/sh
# Incremental dump of all subversion repositories
# make sure to get the subversion environment variables
. /etc/profile.d/subversion.sh
# path to subversion binaries
SVN_BINPATH=${SVN_HOME}/bin
# path to parent of all repositories to be dumped
SVN_REPPATH=/opt/svn/repositories
# destination directory for backup files
DUMP_DIR=/backup/svn
# status directory
SVN_VAR=/home/svn/var
DATETIME=`date +%Y%m%d`
for rep in ${SVN_REPPATH}/*;
do
TSTAMP=`date +%s`
CURR_REV=`${SVN_BINPATH}/svnlook youngest ${rep}`
REP_BASE=`basename $rep`
if [ -e ${SVN_VAR}/status/dates/${REP_BASE}.dt ] ; then
REP_LAST_BK_TSTAMP=`cat ${SVN_VAR}/status/dates/${REP_BASE}.dt`
REP_LAST_BK_REV=`cat ${SVN_VAR}/status/revisions/${REP_BASE}.rev`
else
REP_LAST_BK_TSTAMP=0
REP_LAST_BK_REV=0
fi
if [ ${CURR_REV} -gt ${REP_LAST_BK_REV} ] ; then
echo "**********************************************************"
echo "`date --rfc-2822` - Incremental back up ${rep} : "
echo " oldest revision ${REP_LAST_BK_REV} - newest revision ${CURR_REV}"
echo
DUMPFILE=${DUMP_DIR}/${REP_BASE}-${DATETIME}-${REP_LAST_BK_REV}-${CURR_REV}.dmp
${SVN_BINPATH}/svnadmin --quiet dump $rep --incremental -r${REP_LAST_BK_REV}:${CURR_REV}> ${DUMPFILE}
echo ${TSTAMP} > ${SVN_VAR}/status/dates/${REP_BASE}.dt
echo ${CURR_REV} > ${SVN_VAR}/status/revisions/${REP_BASE}.rev
bzip2 --compress --best ${DUMPFILE}
fi
done
echo
echo `ls -hl ${DUMP_DIR}/*.bz2`
希望这可以帮助。
答案2
由于声誉问题,无法对上述内容发表评论,但所展示的脚本有一个漏洞:每个增量备份中的最后一个修订版本也将作为下一个修订版本转储,即它们重叠一个:例如,
repository-20171115-1-3.dmp # initial dump, contains rev. 1-3
repository-20171116-3-8.dmp # second dump, contains 3-8 (should be 4-8!)
repository-20171116-8-15.dmp # third dump, contains 8-15 (should be 9-15!)
当使用“svn load”命令将转储加载回存储库时,这会导致奇怪的问题 - 它会尝试加载相同的修订版本两次(大部分情况下都无法检测到,但如果文件已被添加或删除,则会失败,因为 svn 会尝试再次执行该操作)。您仍然可以加载这些转储,但您需要明确说明修订范围以忽略每个增量转储中的第一个修订版本。
答案3
请查看更新版本,该版本解决了重叠版本控制的错误。
#!/bin/sh
# Incremental dump of all subversion repositories
# make sure to get the subversion environment variables
. /etc/profile.d/subversion.sh
# path to subversion binaries
SVN_BINPATH=${SVN_HOME}/bin
# path to parent of all repositories to be dumped
SVN_REPPATH=/opt/svn/repositories
# destination directory for backup files
DUMP_DIR=/backup/svn
# status directory
SVN_VAR=/home/svn/var
DATETIME=`date +%Y%m%d`
for rep in ${SVN_REPPATH}/*;
do
TSTAMP=`date +%s`
CURR_REV=`${SVN_BINPATH}/svnlook youngest ${rep}`
REP_BASE=`basename $rep`
if [ -e ${SVN_VAR}/status/dates/${REP_BASE}.dt ] ; then
REP_LAST_BK_TSTAMP=`cat ${SVN_VAR}/status/dates/${REP_BASE}.dt`
REP_LAST_BK_REV=`cat ${SVN_VAR}/status/revisions/${REP_BASE}.rev`
else
REP_LAST_BK_TSTAMP=0
REP_LAST_BK_REV=0
fi
if [ ${CURR_REV} -gt ${REP_LAST_BK_REV} ] ; then
echo "**********************************************************"
echo "`date --rfc-2822` - Incremental back up ${rep} : "
echo " oldest revision ${REP_LAST_BK_REV} - newest revision ${CURR_REV}"
echo
REP_LAST_BK_REV_1=$((REP_LAST_BK_REV+1))
DUMPFILE=${DUMP_DIR}/${REP_BASE}-${DATETIME}-${REP_LAST_BK_REV_1}-${CURR_REV}.dmp
${SVN_BINPATH}/svnadmin --quiet dump $rep --incremental -r${REP_LAST_BK_REV_1}:${CURR_REV}> ${DUMPFILE}
echo ${TSTAMP} > ${SVN_VAR}/status/dates/${REP_BASE}.dt
echo ${CURR_REV} > ${SVN_VAR}/status/revisions/${REP_BASE}.rev
bzip2 --compress --best ${DUMPFILE}
fi
done
echo
echo `ls -hl ${DUMP_DIR}/*.bz2`
````````````````````````````````````````````