开发者

How can I do daily backups for my VisualSVN Repos?

How can I do daily backups for my VisualSVN Repos?

Its on a Windows Ser开发者_如何学Gover 2003 machine, I was thinking about just doing an xcopy of the folder C:\Repo but I'm not familiar enough with svn to know if that will cause issues.

Save me SO!


The proper approach is to use svnadmin hotcopy to create a copy of c:\Repo then archive that copy to tape or off-site storage or whatever. The Subversion Book's chapter on Repository Maintenance has more details.


I do both dump and hotcopy. Put them in a batch file and create a task with Task Scheduler to run it daily. Here is my sample batch file

!backing up credentials
copy H:\Repositories\authz G:\Repo-Backups\7-22-2013\backup
copy H:\Repositories\authz-windows G:\Repo-Backups\7-22-2013\backup
copy H:\Repositories\htpasswd G:\Repo-Backups\7-22-2013\backup

!full dump
svnadmin dump H:\Repositories\Proj1 > G:\Repo-Backups\7-22-2013\dump\Proj1
svnadmin dump H:\Repositories\Proj2 > G:\Repo-Backups\7-22-2013\dump\Proj2 

!hard copy
svnadmin hotcopy H:\Repositories\Proj1 G:\Repo-Backups\7-22-2013\backup\Proj1
svnadmin hotcopy H:\Repositories\Proj2 G:\Repo-Backups\7-22-2013\backup\Proj2 

If you have several repositories (projects) to backup and they change frequently it would be easier to have a little program create the above batch file for you. Here is what I've written for this purpose:

    public static void CreateBackupScript(string srcFolder, string desFolder, bool fullDump)
        { 
if (string.IsNullOrEmpty(srcFolder) || string.IsNullOrEmpty(desFolder))
            return;

        var dateString = DateTime.Now.ToShortDateString().Replace('/', '-');
        var destination = System.IO.Path.Combine(desFolder, dateString, "backup");

        if (!Directory.Exists(destination))
            Directory.CreateDirectory(destination);

        var source = srcFolder + "\\";
        var outputScript = "backup.cmd";
        using (StreamWriter sw = new StreamWriter(outputScript))
        {
            sw.WriteLine("!backing up credentials");
            sw.WriteLine("copy {0}authz {1}", source, destination);
            sw.WriteLine("copy {0}authz-windows {1}", source, destination);
            sw.WriteLine("copy {0}htpasswd {1}", source, destination);

            // dump
            if (fullDump == true)
            {
                sw.WriteLine("!full dump");

                var dumpFolder = System.IO.Path.Combine(desFolder, dateString, "dump");

                if (!Directory.Exists(dumpFolder))
                    Directory.CreateDirectory(dumpFolder);

                foreach (var dir in new DirectoryInfo(source).GetDirectories("*.*", SearchOption.TopDirectoryOnly))
                {
                    sw.WriteLine(@"svnadmin dump {0} > {1}\{2}", dir.FullName, dumpFolder, dir.Name);
                }
            }

            //hot copy
            sw.WriteLine("!hard copy");
            foreach (var dir in new DirectoryInfo(source).GetDirectories("*.*", SearchOption.TopDirectoryOnly))
            {
                sw.WriteLine(@"svnadmin hotcopy {0} {1}\{2}", dir.FullName, destination, dir.Name);
            }
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜