tags:

views:

173

answers:

5

I'd like to make a backup of my SVN repo using tar and ftp from a cronjob once a day. This is quite easy, but I would like to make sure there's no commit etc. running while the backup is made. While there are times of the day / night where this is highly unlikely, but I'd rather not rely on that, because if I'm already up at night in some crunch, the last thing I need is my SVN or my backups getting messed up.

I'm looking for some very simple but effective safeguard. It's OK if SVN clients get an error while the backup is running (it won't take that long). Should I use

  • something on the filesystem level
  • some SVN hook script
  • something else entirely

I started posting this over at serverfault, but then decided that it is slightly closer to programming than to sysadmin, especially if hooks are involved. Feel free to move it if you think otherwise.

A: 

Use svnadmin dump to do a backup, then cURL to FTP upload.

spoulson
It's `svnadmin dump`, not `svndump`. And it's not the best way in this case.
RedGlyph
Oops, you're right. Corrected the command.
spoulson
+3  A: 

svnadmin dump /path/to/repo > repobackup_date

Now you can run tar, gzip, whatever on repobackup_date and svnadmin should take care of controlling access to the repository for you.

To restore, use svnadmin load /path/to/repo < repobackup_date.

Stephen Newell
RedGlyph in his answer suggested using the hotcopy command, were you aware of that command and is there a reason why you would prefer `dump`?
Hanno Fietz
"svnadmin hotcopy" has the advantage of creating a complete copy of the repository including hooks and config. "svn dump" is just content. There is an --incremental option for dump which may be useful if you have a large repository. Personally I use svnadmin dump, 7zip and cURL. Full Dump file uncompressed is currently about 1Gb.
Andrew
I've never used hotcopy, but according to svnadmin help it makes an actual copy of the repo. The reason I would use dump is it provides a flat file will full version history, so you have only one thing to compress and ftp (as opposed to a full directory with many files and folders). I imagine it's mostly a preference thing, but dump also comes in handy when you upgrade your repo or want to switch to a different backend.
Stephen Newell
@Andrew: I think you mean the `--deltas` option :)
RedGlyph
+1  A: 

I do this for all of my production svn repositories.

You should always use svn dump to make a single-file backup of your repository. This makes sure there are no dirty transactions in flight, that could corrupt a filesystem copy. Then just use your favorite ftp app to copy the file over.

I suggest running the results of svn dump through gzip or some other zipping program first.

Mike Miller
+3  A: 

The theoretical way of doing a backup safely is to use the svnadmin hotcopy command (more details here). It basically does a copy of one repository (not a dump, a copy), taking care to block all the operations during that time.

This operation is quite fast, so I shouldn't think any client would have an error, they may experience some delay though (depending on the server load and so on).

You can find an example of script on the Collabnet website.

If you do a dump, besides the huge time it takes, you won't be sure it will done in an atomic way. Dumps are useful to

  • make sure you can migrate from one version to the next - think long-term backups. For example if your server is upgraded from version 1.4 to 1.5, or to 1.6, it's interesting to make a dump then a load of your repositories to take full advantage of the improvements. In some more drastic upgrades it's a necessity because the repository format changes too much.
  • filter files out, or merge repositories, those are more complex operations, out of topic here.

Before opting for a dump, should you prefer that anyway, I encourage you to do the operation manually before, to make sure it is not too long. Make sure also to compress those files, which are much bigger than a repository (hotcopy) - the latter is very well compressed.

RedGlyph
Why are you saying "theoretical"?
Hanno Fietz
Because in practice few people care to do the hotcopy, they just backup the files with their backup tool (which some of the time wouldn't even allow the custom command)...
RedGlyph
Well, it's a buildin command, it probably doesn't get easier, so I'll just use it. Thanks, I wasn't aware of this.
Hanno Fietz
You're welcome - I've added a few lines on dump so that you can see the difference, and maybe you'll need this one for another use later. :-)
RedGlyph
+1 redglyph. For the record, - we do use hotcopy, and thankfully it works fine for us :-)
Critical Skill
A: 

Here there is a a text about repository backup and why you should use svnadmin hotcopy

rcidao