Moving The Local Rsync Repository To The Next Revision

If your Linux distribution is RedHat or one of those that is based on RedHat, such as CentOS, and you set up a yum mirror repository to keep all of the machines at the same distribution level, you will eventually need to move the local repository up to the next revision. Your first clue, that you need to do this, is that the nightly rsync job (that was set up in the "Creating a Local Repository With Rsync" section) fails, probably like this:

     rsync: change_dir "/6.2/updates" (in centos) failed: No such file or
       directory (2)

Not to worry. You can move your mirror repository to the next release quite easily.

But first, before you do, you might want to go around to any systems that you wish to keep at the previous revision and apply any of the updates that you want to apply using the unchanged mirror repository. Once you move the mirror repository up to the next revision, all of the systems that use it will see the new package updates for the next revision and try to apply them. There seems to be no way of going back easily.

Of course, you can revert the /etc/yum.repos.d/CentOS-Base.repo file back to the way it was before you modified it and the standard CentOS repository for your old release will continue to be used as long as that release is supported. Mind you, we recommend that you move up to the latest release and then you won't have any problems but that's up to you. To do that, revert the /etc/yum.repos.d/CentOS-Base.repo file, upgrade to the latest release, upgrade the local repository as outlined below, and then put the changes enabling the local repository back into the CentOS-Base.repo file.

Anyway, the first step in moving the mirror repository up to the next revision is to move the current mirror directory aside so that we can create a new mirror directory for the new release (as above, these notes assume that you are using CentOS and are, therefore, specific to it):

     su
     mv /var/cache/CentOS/6  /var/cache/CentOS/6.2

Replace the numbers 6 and 6.2 with your current revisions of the OS.

Now, create two new directories that will be the local repository for all of the RPM files for the OS and its updates, for the new revison:

     su
     mkdir -p /var/cache/CentOS/6/os/i386
     mkdir -p /var/cache/CentOS/6/updates/i386

This creates the directory structure for the i386 distribution of the OS. If you are using the x86_64 version instead, make these directories:

     su
     mkdir -p /var/cache/CentOS/6/os/x86_64
     mkdir -p /var/cache/CentOS/6/updates/x86_64

Note that, regardless of which point release of the OS you are using, you must only use the major release number in the directory tree. Thus, for CentOS 6.1, 6.2, 6.3, etc., just use 6.

If you'd like to change the permissions on the subdirectory tree, say to give group permissions to one of the worker bees who will maintain it, now's the time to do so. For example:

     su
     chown root:wbee -R /var/cache/CentOS
     chmod g+w -R /var/cache/CentOS

Now, mount the CentOS installation DVD for the new release somewhere and copy all of the relevant files (i.e. for the i386 distribution, copy the i386.rpm and noarch.rpm files, as well as the other files in the i386 .iso or on the i386 DVD). You can either create the two subdirectories and copy the files directly into them from another machine on the network:

     su
     mkdir /var/cache/CentOS/6/os/i386/Packages
     mkdir /var/cache/CentOS/6/os/i386/repodata
     (copy using FTP, NFS or Samba)

Or, you can try mounting the .iso file, in loopback mode, if it is available to you:

     su
     mount -o loop,unhide -t iso9660 \
           -r /my/iso/images/CentOS-6.3-i386-bin-DVD1.iso /mnt
     cp -rp /mnt/Packages /mnt/repodata /var/cache/CentOS/6/os/i386/
     umount /mnt
     mount -o loop,unhide -t iso9660 \
           -r /my/iso/images/CentOS-6.3-i386-bin-DVD2.iso /mnt
     cp -rp /mnt/Packages /var/cache/CentOS/6/os/i386/
     umount /mnt

Or, you can actually mount the DVD directly on the repository machine and do the copy from it, like this:

     su
     mount /dev/cdrom /mnt  (the first DVD)
     cp -rp /mnt/Packages /mnt/repodata /var/cache/CentOS/6/os/i386/
     umount /mnt
     mount /dev/cdrom /mnt  (the second DVD)
     cp -rp /mnt/Packages /var/cache/CentOS/6/os/i386/
     umount /mnt

Again, if you don't like the permissions that got applied to the copied files or preserved from the DVD, you can set them to your liking. For example:

     su
     chown root:wbee -R /var/cache/CentOS/6/os/i386/
     chmod ug=rw,o=r -R /var/cache/CentOS/6/os/i386/
     chmod ugo+x /var/cache/CentOS/6/os/i386/*

The script that keeps the repository up to date, needs to be changed to use the new directory for the updated revision level. Typically, this merely requires that you edit the existing file with your text editor and change the revision level:

/etc/cron.daily/yum-repos-update:

.

       .

#
# Run rsync to synchronize the current CentOS 6 local repository with the # remote repository.
#
if [ ${SERVERROLE} != "Secondary" ] ; then

      /usr/local/bin/rsync -av --delete \
          --exclude-from=/var/cache/CentOS/6/CentOS-6.3.excludes \
          rsync://your.rsync.mirror.server/centos/6.3/updates/i386 \
          --exclude=debug/ /var/cache/CentOS/6/updates/ > /dev/null
      chown root:wbee -R /var/cache/CentOS/6/updates/
      chmod g+w -R /var/cache/CentOS/6/updates/

fi

Since we already created the exclude file when we originally set up the yum mirror repository, we simply need to copy it to the new mirror directory:

     su
     cp /var/cache/CentOS/6.2/CentOS-6.2.excludes \
        /var/cache/CentOS/6/CentOS-6.3.excludes
     chown root:wbee /var/cache/CentOS/6/CentOS-6.3.excludes
     chmod ug=rw,o=r /var/cache/CentOS/6/CentOS-6.3.excludes

Next, you should prime the new repository by running the update once, manually:

     su
     /etc/cron.daily/yum-repos-update

It will probably take several hours and afterwards there should be quite a few files in your updates directory that look like this:

     /var/cache/CentOS/6/updates/i386/drpms
                                     /drpms/389-ds-base-1.2.10.2...i686.drpm
                                            apr-1.3.9-3...i686.drpm
                                            bind-chroot-9.7.0...i686.drpm
                                                 .
                                                 .
                                                 .
                                     /Packages
                                     /Packages/389-ds-base-1.2.10.2...i686.rpm
                                               apr-1.3.9-5.el6_2.i686.rpm
                                               bind-9.8.2-0.10...i686.rpm
                                                    .
                                                    .
                                                    .
                                     /repodata
                                     /repodata/0041b...lists.sqlite.bz2
                                               00446...-prestodelta.xml.gz 00787...-primary.xml.gz
                                                    .
                                                    .
                                                    .

You can visually check that the files were mirrored properly by looking at the remote HTML directory that corresponds to the rsync directory. As before, if you follow the directory tree down to the repodata and RPMS directories, you'll see all of the files that should have been mirrored. Inspect a few names to see if they all appear to be present.

Note that, as usual, if your repository is 64-bit, you should replace "i386" wherever it appears, above, with "x86_64".

At this point, all of the machines that were using the original mirror repository will begin using the new one and any updates that are applied on them will move the system up to the next revision level. On any of these machines, we can run yum to see if the new repository works:

     su
     yum clean all
     yum update

If all runs well, you have properly upgraded the local CentOS repository.