6

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?

1

3 Answers 3

7

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.

5
  • Did you mean "like any other bunch of files" ?
    – Tim Long
    May 28, 2010 at 22:03
  • @Tim Long - Rectified. I think I may have intended to write "not unlike". If you see this sort of thing in my questions or answers please feel free to edit them. May 28, 2010 at 23:04
  • Would have edited, but only having a 'mere' 694 rep is not enough to edit.
    – Tim Long
    May 29, 2010 at 20:42
  • It may be "a bunch of files" but those files are interdependent and cannot be copied instantaneously. Which could cause a "faulty backup". See my answer for the SVN documented solution. May 31, 2010 at 4:07
  • 1
    @Bryan, VSS should take care of the interdependence issue because it effectively takes a point in time snapshot prior to the backup. I certainly haven't experienced any issues doing my backups (and test restores) that way. May 31, 2010 at 4:31
3

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.

2

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);
            }
        }
    }
1
  • +1 - this is very similar to how we back up our SVN repo's Jul 23, 2013 at 4:50

Not the answer you're looking for? Browse other questions tagged .