0

We have a RPM repository (on a Centos 6 machine) that we need to push to another machine. So far we've been using rsync -av --delete to simply push the repo directory over the network. This makes the remote repository unusable during the sync - before rsync finishes, repodata don't match the present rpm packages and the synchronization of repodata is also not atomic.

How can I synchronize two repositories atomically over ssh?

I would like the remote repository to be usable at any time, even during the transfer of data. I know I could achieve this copying the repo to a temporary directory, and then moving/symlinking it, but it feels like there should be a better solution.

Mifeet
  • 111
  • 5

2 Answers2

1

Use reposync from the yum-utils package. man page. I think it still works with dnf if your yum got replaced by that.

reposync is a python script. We can see it does

# Lock if they've not given an explicit cachedir
...
my.doLock()

and if we look at pydoc yum.YumBase there is

doLock(self, lockfile='/var/run/yum.pid')
  Acquire the yum lock.

so it seems to lock against other yum accesses, which may not be what you want.

meuh
  • 1,563
  • 10
  • 11
  • Looking at the man page: "synchronize yum repositories to a local directory". I guess I would have to run this from the remote (target) machine? I only have ssh access in one direction, i.e. source repo -> target repo (unless I tunnel stuff). – Mifeet May 19 '16 at 17:05
  • Also, does reposync ensure the change is atomic? I.e. during synchronization, the updated repo can be used even during synchronization? – Mifeet May 19 '16 at 17:06
  • @Mifeet It locks for yum accesses, see my edit, but perhaps you are doing some other accesses. – meuh May 19 '16 at 17:43
0

A close way would be to rsync to another directory name, then do a couple of quick mv's:

rsync -avP repo remote-machine:/dir/repo.new
ssh remote-machine "mv /dir/repo /dir/repo.old; mv /dir/repo.new /dir/repo"

Then you could remove the old directory when you wish. The time that the repo would be unavailable/inconsistent would be minimized.

lsd
  • 1,673
  • 10
  • 10