How can I do daily backups for my VisualSVN Repos? [duplicate]

How can I do daily backups for my VisualSVN Repos?

Its on a Windows Server 2003 machine with VisualSVN Server, 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.

Should I use dump or hotcopy or both?


Solution 1:

It's a bunch of files, like any other bunch of files. Use whatever method you use to backup the rest of the system. As this is on a server I would have thought it would already be included in the regular backup scheme.

If you're using half-decent backup software, even Windows own NT Backup, it should be using the Volume Shadow Copy service, which will take care of open file issues, if any.

Solution 2:

Just copying the repo files is a bad idea:

...unless you temporarily disable all other access to your repository, simply doing a recursive directory copy runs the risk of generating a faulty backup.

You should use the The svnadmin hotcopy command.

Repository Maintenance > Repository Backup

You could script this and run it as a scheduled task.

Solution 3:

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);
            }
        }
    }