Centos – Synchronize RPM repository atomically

centosrepositoryrpmyum

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.

Best Answer

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.