You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Bo Berglund <bo...@gmail.com> on 2021/01/13 11:16:17 UTC

How to safely back up an svn repository on ubuntu?

I would like to set up a cron job to backup the repositories on an svn server to
a Synology NAS.

The repositories reside in /var/lib/svn and comprise about 6 Gb worth of files
in 12 different directories.
These are svnsync:ed nightly from our main SVN server in the main office across
the world as a backup of the development activities there.
The main svn server is VisualSvn on Windows Server 16 if that matters. The
svnsync has worked fine for 2+ years since I set it up.

The backup SVN server runs on an Ubuntu 18.4 LTS server in my home network and
on that network I also have a Synology NAS, which I want to use as a 3rd level
backup for the SVN repositories in case the Ubuntu server here crashes.

I got a problem with it a few days ago when we had a power outage and the Ubuntu
box did not boot properly when power returned. Now fixed but it raised the
concern over backup security.

I have now set up an NFS connection between the Ubuntu server and the Synology
NAS so I have a target dir in Ubuntu in /nfs/backup where I can write the files.

So what I had in mind is to somehow keep a copy of the repository files on the
nfs share but I am not sure what command would be suitable to perform this
action.

I could use tar but that would be complex since there are certainly not many
files that change from one day to the other. Only changed files should be copied
to reduce the time of backup.
Or else perhaps rsync, provided it knows which files have changed and which have
not etc.

I am a user of Ubuntu Linux for some of my work and have had to learn the basics
of managing Linux, but I am not versed in these actions. Daily I am a Windows
user.

I don't know if some actions should be done towards svn on the ubuntu server in
order to safely copy the files either...

Please advice...


-- 
Bo Berglund
Developer in Sweden


RE: How to safely back up an svn repository on ubuntu?

Posted by Juan Gabriel Covas <jg...@softline.es>.
If it helps, I use the following one-liner to "svnadmin hotcopy --incremental", so only new revisions are copied each time (the svn-hot-copies target path is a NFS mount, for example, in other box)

# find /path/to/your/repos -maxdepth 1 -mindepth 1 -type d -printf "%f\0" | sort -z | xargs -0 -I % sh -c 'echo %; svnadmin hotcopy --incremental /path/to/your/repos/% /path/to/svn-hot-copies/repos/%;'

Regards,

Juan G. Covas
Balearic Islands

De: Mark Phippard <ma...@gmail.com> 
Enviado el: miércoles, 13 de enero de 2021 12:54
Para: Bo Berglund <bo...@gmail.com>
CC: Subversion <us...@subversion.apache.org>
Asunto: Re: How to safely back up an svn repository on ubuntu?

On Wed, Jan 13, 2021 at 6:16 AM Bo Berglund <ma...@gmail.com> wrote:
I would like to set up a cron job to backup the repositories on an svn server to
a Synology NAS.

The repositories reside in /var/lib/svn and comprise about 6 Gb worth of files
in 12 different directories.
These are svnsync:ed nightly from our main SVN server in the main office across
the world as a backup of the development activities there.
The main svn server is VisualSvn on Windows Server 16 if that matters. The
svnsync has worked fine for 2+ years since I set it up.

The backup SVN server runs on an Ubuntu 18.4 LTS server in my home network and
on that network I also have a Synology NAS, which I want to use as a 3rd level
backup for the SVN repositories in case the Ubuntu server here crashes.

I got a problem with it a few days ago when we had a power outage and the Ubuntu
box did not boot properly when power returned. Now fixed but it raised the
concern over backup security.

I have now set up an NFS connection between the Ubuntu server and the Synology
NAS so I have a target dir in Ubuntu in /nfs/backup where I can write the files.

So what I had in mind is to somehow keep a copy of the repository files on the
nfs share but I am not sure what command would be suitable to perform this
action.

I could use tar but that would be complex since there are certainly not many
files that change from one day to the other. Only changed files should be copied
to reduce the time of backup.
Or else perhaps rsync, provided it knows which files have changed and which have
not etc.

I am a user of Ubuntu Linux for some of my work and have had to learn the basics
of managing Linux, but I am not versed in these actions. Daily I am a Windows
user.

I don't know if some actions should be done towards svn on the ubuntu server in
order to safely copy the files either...

I would use rsync. Especially since this sounds like it is mainly a last resort backup. There are some relatively minor problems that can happen if rsync happens to run in the middle of a transaction.  The rsync still works but it could make a backup of the repository in an incomplete state. Those problems are fixable and the next rsync would still work and would fix the problem too.

The safer way is to use svnadmin hotcopy but you would have to script it since you need to run it for each repository. The advantage of rsync is that you can just process the entire root folder where your repositories are stored.

-- 
Thanks

Mark Phippard
http://markphip.blogspot.com/

Re: How to safely back up an svn repository on ubuntu?

Posted by Mark Phippard <ma...@gmail.com>.
On Wed, Jan 13, 2021 at 6:16 AM Bo Berglund <bo...@gmail.com> wrote:

> I would like to set up a cron job to backup the repositories on an svn
> server to
> a Synology NAS.
>
> The repositories reside in /var/lib/svn and comprise about 6 Gb worth of
> files
> in 12 different directories.
> These are svnsync:ed nightly from our main SVN server in the main office
> across
> the world as a backup of the development activities there.
> The main svn server is VisualSvn on Windows Server 16 if that matters. The
> svnsync has worked fine for 2+ years since I set it up.
>
> The backup SVN server runs on an Ubuntu 18.4 LTS server in my home network
> and
> on that network I also have a Synology NAS, which I want to use as a 3rd
> level
> backup for the SVN repositories in case the Ubuntu server here crashes.
>
> I got a problem with it a few days ago when we had a power outage and the
> Ubuntu
> box did not boot properly when power returned. Now fixed but it raised the
> concern over backup security.
>
> I have now set up an NFS connection between the Ubuntu server and the
> Synology
> NAS so I have a target dir in Ubuntu in /nfs/backup where I can write the
> files.
>
> So what I had in mind is to somehow keep a copy of the repository files on
> the
> nfs share but I am not sure what command would be suitable to perform this
> action.
>
> I could use tar but that would be complex since there are certainly not
> many
> files that change from one day to the other. Only changed files should be
> copied
> to reduce the time of backup.
> Or else perhaps rsync, provided it knows which files have changed and
> which have
> not etc.
>
> I am a user of Ubuntu Linux for some of my work and have had to learn the
> basics
> of managing Linux, but I am not versed in these actions. Daily I am a
> Windows
> user.
>
> I don't know if some actions should be done towards svn on the ubuntu
> server in
> order to safely copy the files either...
>

I would use rsync. Especially since this sounds like it is mainly a last
resort backup. There are some relatively minor problems that can happen if
rsync happens to run in the middle of a transaction.  The rsync still works
but it could make a backup of the repository in an incomplete state. Those
problems are fixable and the next rsync would still work and would fix the
problem too.

The safer way is to use svnadmin hotcopy but you would have to script it
since you need to run it for each repository. The advantage of rsync is
that you can just process the entire root folder where your repositories
are stored.

-- 
Thanks

Mark Phippard
http://markphip.blogspot.com/

Re: How to safely back up an svn repository on ubuntu?

Posted by Daniel Sahlberg <da...@gmail.com>.
Den ons 13 jan. 2021 kl 12:16 skrev Bo Berglund <bo...@gmail.com>:

> Please advice...
>

You can probably get started by taking a look at the Repository Backup
section of the SVN Book
http://svnbook.red-bean.com/nightly/en/svn.reposadmin.maint.html#svn.reposadmin.maint.backup

//Daniel

Re: How to safely back up an svn repository on ubuntu?

Posted by Pierre Fourès <pi...@gmail.com>.
Le mer. 13 janv. 2021 à 23:25, Bo Berglund <bo...@gmail.com> a écrit :
>
> On Wed, 13 Jan 2021 12:58:59 +0100, Pierre Fourès <pi...@gmail.com>
> wrote:
>
> Thanks for your comments Pierre! :)
>

You're welcome.

> So you mean I need to shut down the svn server first?
> I don't know how to do that since svn is kind of integrated with apache on my
> server...

This might look a bit harsh, but I basically shutdown the apache
service, rsync the files, and then restart the apache service. Some
years ago, I eventually admitted to myself that I really can offer me
the ease of not having to reach some kind of high availability, or
even good availability on this service. I decided to reach for ease of
setup, ease of maintenance and reliability.

My current setup is running on a old containerized Debian I will
upgrade next month, so there is not systemd, and it looks like :
service apache2 stop && rsync params && service apache2 start
which will soon turn into :
systemctl stop apache2 && rsync params && systemctl start apache2

I use && in order not to restart the apache server if something bad
happened. I have a external probe on the server checking that apache
running. If apache doesn't restart for whatever reason, I get an email
(optionally an sms) telling me something bad happened.

This might look against what most would call a nice setup, but I find
it very anti-fragile and simple to handle. At least two things could
mess up (rsync and restart), but I only probe the end result in a tied
execution. I seek for a fail-fast and fail-clean approach. I tried to
restrict how many cogs was at play in my system, and how many wrong
paths the thing could go into. I will have to think a little more for
systemd as there is more subtleties.

> OTOH I know exactly when the nightly svnsync is started on the source system to
> copy over the day's changes to the backup server, so I could choose another time
> to run my cron job.
> And this backup svn server on Ubuntu is not used for anything on the synced
> repositories except receiving the backup data.

It looks you can offer yourself the same ease.

>
> Concerning rsync, I have first tested what is happening when I use ordinary file
> system commands towards the nfs share on Synology...
>
> What I found was that the owner/group fields look strange to me.
> Here an example:
>
> $ ls -l ~/www/index.php
> -rw-rw-r--  1 bosse bosse        177 Jan 13 21:32 index.php
>
> $ cp ~/www/index.php /nfs/backup/
>
> Then:
> $ ls -l /nfs/backup/
> -rw-rw-r-- 1 nobody 4294967294  177 Jan 13 23:04 index.php
>
> Notice how the file ownership has changed in this operation.
> Is rsync doing something else that keeps the ownership the same as on the
> source?
> Or have I set up the wrong kind of options on the mount command for the nfs
> share?

I'm really not an expert of NFS, and in order to restrict even further
the cogs at play in my systems, I prefer to use a simple rsync over
ssh/scp, instead of mounting a nfs share on the svn server. Basically
all my server have ssh, and this skip me having to install (and
understand) all the specifics of NFS. More over, I even don't have to
care where my remote server is, as the endpoint will more easily be
reachable and the communication will be encrypted over the wire. I
just have to put the svn-server public key on the authorized_keys of
the backup server, and manually accept the backup-server fingerprint
on the first rsync I run from the svn-server. Then I'm done setting up
"the share".

Doing so, and eventually setting up a reverse rsync command to grab
back the files on the svn-server, I don't really mind the file's
ownership. On the remote backup-server, the owner will be the one used
to connect with through ssh/scp. On the restore, you may configure
rsync to set precisely what you require, but, if I recall fine, it
will basically be the user:group of the one running the rsync command.
If you don't run rsync as root, but as the user meant to own the data,
you should be fine. In our case, the user should be www-data. One easy
way to "downcast" the user running your command launched from a cron
script is to simply use two scripts, the launcher, run as root, which
in turn launch the unprivileged script through the command :
su -c "time bash $mypath/$myscript.sh" www-data 2>&1 > $log_file

There might be a lot of other ways to do, but, to me, this gets the
job done in a very easy to remember, understand and replicate
approach. My unprivileged script isn't even set to executable. This
prevent me to accidentally call it by mistake, as this script is only
meant to be run by cron (or through conscious manual execution, like
on the first run).

My current rsync command looks like :
rsync -avhW $path_to_svn_repos/ $user@$bkp_srv:$path_to_svn_bkp/$rolling_index/

I use the -W flag, as I wanted to copy wholes files only, and not use
the delta algorithm, as the svn repository format is (mostly, fully ?)
append only. I had to check my notes and the man page to recall what
the -W was. I guess I will remove this "premature optimisation" (and
extra cog) when I will reinstall my svn infrastructure.

> I don't think I will need a rolling scheme here...
>

Then you will have an even simpler and anti-fragile solution than mine. ;)

Pierre.

Re: How to safely back up an svn repository on ubuntu?

Posted by Bo Berglund <bo...@gmail.com>.
On Wed, 13 Jan 2021 12:58:59 +0100, Pierre Fourès <pi...@gmail.com>
wrote:

Thanks for your comments Pierre! :)

>I understand your point and have done similar setup. I've first started
>using a local svnadmin hotcopy to create a clean and safe copy of my
>repository, and then, rsynced this folder to my remote server. As I can
>handle a downtime on my svn server (in the middle of the night), I've
>switched to shutting down the server, and just rsyncing the /var/lib/svn
>sub-folders. This saved a step, a loop, and some disk usage on my local
>server.

So you mean I need to shut down the svn server first?
I don't know how to do that since svn is kind of integrated with apache on my
server...
OTOH I know exactly when the nightly svnsync is started on the source system to
copy over the day's changes to the backup server, so I could choose another time
to run my cron job.
And this backup svn server on Ubuntu is not used for anything on the synced
repositories except receiving the backup data.


Concerning rsync, I have first tested what is happening when I use ordinary file
system commands towards the nfs share on Synology...

What I found was that the owner/group fields look strange to me.
Here an example:

$ ls -l ~/www/index.php
-rw-rw-r--  1 bosse bosse        177 Jan 13 21:32 index.php

$ cp ~/www/index.php /nfs/backup/

Then:
$ ls -l /nfs/backup/
-rw-rw-r-- 1 nobody 4294967294  177 Jan 13 23:04 index.php

Notice how the file ownership has changed in this operation.
Is rsync doing something else that keeps the ownership the same as on the
source?
Or have I set up the wrong kind of options on the mount command for the nfs
share?

>As an extra-layer of security, what you might consider too, on your
>cold-backup NAS system, is to set up a rolling backup strategy scheme. I
>was afraid of a corruption of my repositories, for which ever reason, but
>mostly from a mistake from my own self. Having multiple copies on my cold
>storage helps preventing it. Just using the day of the week while selecting
>which folder you want to rsync your files too makes you a 7 days rolling
>scheme.
>

I don't think I will need a rolling scheme here...


-- 
Bo Berglund
Developer in Sweden


Re: How to safely back up an svn repository on ubuntu?

Posted by Pierre Fourès <pi...@gmail.com>.
Hi Bo,

I understand your point and have done similar setup. I've first started
using a local svnadmin hotcopy to create a clean and safe copy of my
repository, and then, rsynced this folder to my remote server. As I can
handle a downtime on my svn server (in the middle of the night), I've
switched to shutting down the server, and just rsyncing the /var/lib/svn
sub-folders. This saved a step, a loop, and some disk usage on my local
server.

As an extra-layer of security, what you might consider too, on your
cold-backup NAS system, is to set up a rolling backup strategy scheme. I
was afraid of a corruption of my repositories, for which ever reason, but
mostly from a mistake from my own self. Having multiple copies on my cold
storage helps preventing it. Just using the day of the week while selecting
which folder you want to rsync your files too makes you a 7 days rolling
scheme.

Pierre.

Le mer. 13 janv. 2021 à 12:16, Bo Berglund <bo...@gmail.com> a écrit :

> I would like to set up a cron job to backup the repositories on an svn
> server to
> a Synology NAS.
>
> The repositories reside in /var/lib/svn and comprise about 6 Gb worth of
> files
> in 12 different directories.
> These are svnsync:ed nightly from our main SVN server in the main office
> across
> the world as a backup of the development activities there.
> The main svn server is VisualSvn on Windows Server 16 if that matters. The
> svnsync has worked fine for 2+ years since I set it up.
>
> The backup SVN server runs on an Ubuntu 18.4 LTS server in my home network
> and
> on that network I also have a Synology NAS, which I want to use as a 3rd
> level
> backup for the SVN repositories in case the Ubuntu server here crashes.
>
> I got a problem with it a few days ago when we had a power outage and the
> Ubuntu
> box did not boot properly when power returned. Now fixed but it raised the
> concern over backup security.
>
> I have now set up an NFS connection between the Ubuntu server and the
> Synology
> NAS so I have a target dir in Ubuntu in /nfs/backup where I can write the
> files.
>
> So what I had in mind is to somehow keep a copy of the repository files on
> the
> nfs share but I am not sure what command would be suitable to perform this
> action.
>
> I could use tar but that would be complex since there are certainly not
> many
> files that change from one day to the other. Only changed files should be
> copied
> to reduce the time of backup.
> Or else perhaps rsync, provided it knows which files have changed and
> which have
> not etc.
>
> I am a user of Ubuntu Linux for some of my work and have had to learn the
> basics
> of managing Linux, but I am not versed in these actions. Daily I am a
> Windows
> user.
>
> I don't know if some actions should be done towards svn on the ubuntu
> server in
> order to safely copy the files either...
>
> Please advice...
>
>
> --
> Bo Berglund
> Developer in Sweden
>
>