我如何逐步进行 SVN 存储库备份....我想备份存储库本身....我不想将其备份为文件夹....
答案1
步骤1 创建运行命令的脚本或批处理文件
svnadmin dump REPOS_PATH > backupfile
svnadmin 是 svn 自带的一个程序,它位于 bin 文件夹中
backupfile 是存储库将被转储到的文件
REPOS_PATH 是存储库的位置
看http://svnbook.red-bean.com/en/1.1/re31.html更多细节
第2步。 运行脚本/批处理文件来测试备份。
步骤3. 通过运行命令测试备份是否有效
svnadmin load test_path < backupfile
现在尝试在 test_path 中创建的存储库以确保它正常工作 - 它应该可以与较新版本的 svn 一起使用。
答案2
按照您可以另存为的脚本:svnbackup.sh
#!/bin/bash
appname=`basename $0`
#
# Set some defaults
#
increment=100
start=""
default_history_file="last_saved"
history_file=""
dumpfilepath="."
dumpfilename="dumpfile"
verbose=false
sshopts=""
identity=""
#
# Function to explain how to use the program
#
function usage () {
echo
echo "$appname [-h]"
echo "$appname [-v] [-i increment] [-s start_rev] [--scp remote] [--identity ssh-key] [--ssh-opts ssh options] [--history-file file] [--out-dir directory name] [--compress (gzip|bzip2)] [--file-name dumpfile-base-name] svn_repository_path"
cat - <<EOF
This script dumps a subversion repository to a series of compressed
files. It uses a local file to remember the last changeset dumped so
the script can be used to generate files for backups.
Using the --scp option, the backup files can be generated on one
machine and copied to a backup server once dumped.
-v -- Verbose mode
-i increment -- How many revisions to include in each dump file.
--file-name base -- Base name for dump files, defaults to "dumpfile".
-s start_rev -- First revision to dump.
--scp remote -- Location for remote backups. Files are transfered via scp,
then removed from the local directory.
--identity -- Identity file for scp transfer
--ssh-opts -- options to use for scp
--history-file -- path and filename of historyfile to use
--out-dir -- path where svn dump files should be written, defaults to "."
--compress -- compression method (gzip or bzip2, defaults to bzip2)
EOF
echo
echo "Example:"
echo " $appname -v -i 100 --scp user@backupserver:/backups/svn /svn/Project"
echo
exit $1
}
compress_app="bzip2"
compress_ext="bzip2"
#
# Process arguments
#
while [ $# -gt 0 ]
do
opt="$1"
case "$opt" in
-h) usage 0;;
-i) increment=$2;
shift;;
-s) start=$2;
shift;;
--scp) dest="$2";
shift;;
--identity) identity="$2";
shift;;
--ssh-opts) sshopts="$2";
shift;;
--history-file) history_file="$2";
shift;;
--out-dir) dumpfilepath="$2";
shift;;
--file-name) dumpfilename="$2";
shift;;
-v) verbose=true;;
--compress)
case "$2" in
bzip2|bz|bzip)
compress_app="bzip2";
compress_ext="bzip2";;
gzip|gz)
compress_app="gzip";
compress_ext="gz";;
esac;
shift;;
*) break;;
esac
shift
done
repository="$1"
if [ -z "$repository" ]
then
echo "Failed: Repository argument required"
usage 1
fi
if [ -z "$history_file" ]
then
history_file="$dumpfilepath/$default_history_file"
fi
if [ "x${start}" = "x" ]
then
# if [ -s $history_file ] #Blocco Rinominato per NON Tenere Conto Last_saved
# then
# loop_first=`cat $history_file`
# else
# loop_first=0
# fi
loop_first=0
else
loop_first=$start
fi
youngest=`svnlook youngest "$repository"`
$verbose && echo "Backing up: $repository"
$verbose && echo " From: $loop_first"
$verbose && echo " To: $youngest"
if [ "$dest" != "" ]
then
$verbose && echo " Dest: $dest"
fi
if [ "$identity" != "" ] ; then
$verbose && echo " Identity: $identity"
fi
if [ "$sshopts" != "" ] ; then
$verbose && echo " ssh opts: $sshopts"
fi
$verbose && echo "Hist. file: $history_file"
$verbose && echo "Chunk size: $increment"
#
# Function to do the backup for one set of revisions
#
function backup_revs () {
typeset first=$1
typeset last=$2
typeset repo=$3
if [ "$first" != "0" ]
then
incremental="--incremental"
fi
repo_name=`basename "$repo"`
dumpfile="$dumpfilepath/${dumpfilename}-${repo_name}-${first}-${last}.${compress_ext}"
$verbose && echo -n "Dumping ${first}:${last} ..."
svnadmin dump -q "$repo" $incremental --revision ${first}:${last} \
| "$compress_app" > "$dumpfile"
RC=$?
$verbose && echo
if [ $RC -ne 0 ]
then
rm -f "$dumpfile"
return $RC
fi
$verbose && echo "Created $dumpfile"
if [ "$dest" != "" ]
then
if [ -z "$identity" ] ; then
scp $sshopts "$dumpfile" "$dest"
else
scp $sshopts -i $identity "$dumpfile" "$dest"
fi
RC=$?
rm -f "$dumpfile"
fi
return $RC
}
#
# Do the incremental dumps
#
if [[ $youngest -eq $loop_first ]]
then
$verbose && echo "No new changesets to dump"
exit 0
fi
let loop_last=($loop_first + $increment)
if [[ $loop_first -ne 0 ]]
then
let loop_first=($loop_first + 1)
fi
while [[ $loop_first -le $youngest ]]
do
if [ $loop_last -lt $youngest ]
then
# A full "increment"
backup_revs $loop_first $loop_last "$repository" || exit 1
#echo $loop_last > $history_file
else
# In case the last few revs do not make up a full "increment"
backup_revs $loop_first $youngest "$repository" || exit 1
#echo $youngest > $history_file
fi
let loop_first=($loop_last + 1)
let loop_last=($loop_last + $increment)
done
exit 0
答案3
- 停止服务器运行
- 复制包含 repo、hooks 和配置文件的整个目录。
- 如果您使用 Apache 配置并且它没有存储在上述目录中,也请复制它。
就是这样。
您可以在同一台机器或类似的机器上进行恢复(例如,windows -> windows)。如果您想从 Windows 恢复到 Linux(例如),那么您将需要转储并加载存储库。您仍然需要复制目录的其余部分。
建议使用 rsync 复制所有内容(但您必须停止服务器才能始终获得良好的备份),或者使用 svnsync,它是 SVN 的出色增量备份实用程序。(您仍然必须复制钩子和配置 - 我使用 rsync 复制它们并使用 svnsync 复制 repo)
答案4
只需创建 svn 目录的副本。
编辑:
正如前面提到的 - 您需要先停止 svn 服务器。
如果您使用 apache 和 ssh 来访问您的 repo,那么您也需要停止它们。