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?

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
Tyler
  • 249
  • 1
  • 6
  • 12

3 Answers3

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.

John Gardeniers
  • 27,262
  • 12
  • 53
  • 108
  • Did you mean "_like_ any other bunch of files" ? – Tim Long May 28 '10 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. – John Gardeniers May 28 '10 at 23:04
  • Would have edited, but only having a 'mere' 694 rep is not enough to edit. – Tim Long May 29 '10 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. – Byran Zaugg May 31 '10 at 04: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. – John Gardeniers May 31 '10 at 04:31
  • +1 @John, I was not aware VSS did that. Thank you. – Byran Zaugg Jun 01 '10 at 04:18
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.

Byran Zaugg
  • 337
  • 1
  • 2
  • 10
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);
            }
        }
    }
slm
  • 7,355
  • 16
  • 54
  • 72
Kam
  • 121
  • 1