One-shot Yum Command To Match Rpms Between Systems?

Home » CentOS » One-shot Yum Command To Match Rpms Between Systems?
CentOS 14 Comments

Given a list of rpms on one system (rpm -qa > list.txt), is there a one-shot command that I can run on another system to remove all of the rpms not listed and add any that are on the list and not present on the second system?

14 thoughts on - One-shot Yum Command To Match Rpms Between Systems?

  • one-shot command that I can run on another system to remove all of the rpms not listed and add any that are on the list and not present on the second system?

    If you had an internal repo of these packages you could yum distro-sync … otherwise there is no one shot command to do this given a list.

    And of course as will be pointed out by many the only right answer is yum update anyway given cherry picking updates is not supported.

  • The objective is not to cherry pick updates, but rather to install a second system with packages that match the first system. After fine-tuning the installed packages and stripping out the unnecessary stuff, it would be nice to just say “make that system look like this one” — rsync for yum if you will. The specific package versions aren’t important at that stage since I can run yum update after the initial installation.

  • It wouldn’t be a one liner except in the most general sense that you can string multiple bash commands with “;”, but I’m sure someone can do something clever with uniq(1).

    Noam

  • I’d probably turn it into a puppet manifest or ansible playbook, and use that to install the packages. I’d not use rpm -qa unadorned, though, but rpm -qa –qf “%{NAME}.%{ARCH}\n”.

  • yum second system with packages that match the first system. After fine-tuning the installed packages and stripping out the unnecessary stuff, it would be nice to just say “make that system look like this one” — rsync for yum if you will. The specific package versions aren’t important at that stage since I can run yum update after the initial installation.

    Well if you’re planning on doing a yum update anyway just cat rpmlist |
    xargs yum -y install

    Better solution to this though is a basic ansible task list defining what you need.

  • I think you can pull this off with `yum shell`. First, though, don’t do
    `rpm -qa` as your list — do `rpm -qa –qf ‘%{name}.%{arch}\n’|sort` instead. That way, version numbers won’t complicate things.

    And then, on the second system (the one you want to change), try this crazy oneliner:

    ( rpm -qa –qf ‘%{name}.%{arch}\n’ | sort | diff –old-line-format=’install %L’ –new-line-format=’remove %L’ -unchanged-line-format=” list.txt – ; echo run ) | yum shell

    It’s not really as bad as it looks — the diff formatting is just verbose. The first command just gets the package list from the current system; then we sort it, and then get the difference in a formatted as a list of “install” and “remove” commands. Then add “run” to the end, and pipe all of that to yum shell.

    This is totally untested but I’ll give it good odds of working. :)


    Matthew Miller

    Fedora Project Leader

  • Jonathan Billings писал 2016-05-18 20:16:

    You can either use the tools suggested or write a simple helper script. Diff sorted list of packages on these two systems (using
    “%{NAME}.%{ARCH}” format). Add the packages in lines starting with “<", remove the packages in lines starting with ">“. Sort of.

  • I meant comm(1), by the way, although the other answers in this thread, especially the “yum shell” based ones, are cleaner.

    Noam

  • –4lJjfxEwc5i32jIF5d3IHgGoEiXS4Rqor Content-Type: text/plain; charset=windows-1252
    Content-Transfer-Encoding: quoted-printable

    So, reinstall it from scratch, a minimal install, then yum install the package list .. obviously if you want to mirror on the second machine exactly what is on the other system, whats on it now is irrelevant (right?).

    Yum is a tool to install stuff, it is not a configuration management tool. They make configuration management programs as well. Ansible, Puppet, Salt (all with or without Foreman) and several other things can do what you want to manage system configurations.

    If you don’t want to reinstall that other machine from scratch .. You can create a filelist using rpm -qa from each machine .. use diff of those filelists to figure out what is on the second machine you don’t want (it will have a + or a – in the diff file, depending on how you run the command). The things you want on the second machine which are not there will have the opposite sign.

    Then you can rpm -e .. then yum install and be done.

    But learning configuration management and getting required packages tied to specific roles will the better in the end, as you can take a data backup and a configuration management system .. push a button (or issues a command) and build out a new machine with all the services already setup, then restore ‘data’ and be back online.

    –4lJjfxEwc5i32jIF5d3IHgGoEiXS4Rqor

  • –pmsL2bvnroAfq1a74xNGVQKGq9of8tfU9
    Content-Type: text/plain; charset=utf-8
    Content-Transfer-Encoding: quoted-printable

    Right .. if you are not at the same update levels then name.arch is better than full versions.

    –pmsL2bvnroAfq1a74xNGVQKGq9of8tfU9

  • Frank Cox wrote:
    Two solutions, both of which we use here at work.

    1. rpm -qa > file; minimal on new machine, and yum -y install $(cat file).
    2. a) on new machine, mkdir /new /boot/new
    b) from old machine,
    sync -HPavzx –exclude=/old –exclude=/var/log/wtmp
    –exclude=/var/log/lastlog $newmachine:/. /new/.
    rsync -HPavzx $machine:/boot/. /boot/new/.

    c) then:
    rsync -HPavzx /etc/sysconfig/network-scripts/ifcfg-eth*
    /new/etc/sysconfig/network-scripts rsync -HPavzx /etc/sysconfig/hwconf /new/etc/sysconfig rsync -HPavzx /boot/grub/device.map /boot/new/grub/
    rsync -HPavzx /etc/udev/rules.d/70-persistent-net.rules
    /new/etc/udev/rules.d/
    rsync -HPavzx /etc/ssh/ssh_host* /new/etc/ssh

    d) zsh zmodload zsh/files

    cd /boot mkdir old mv * old mv old/lost+found . mv old/new/* .

    # Root partition. cd /
    mkdir old mv * old mv old/lost+found . mv old/root mv old/new/* . sync sync And reboot.

    mark