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?
On 18 May 2016 07:55, "Frank Cox" theatre@melvilletheatre.com wrote:
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?
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.
On Wed, 18 May 2016 09:30:54 +0100 James Hogarth wrote:
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.
On 18 May 2016 17:57, "Frank Cox" theatre@melvilletheatre.com wrote:
On Wed, 18 May 2016 09:30:54 +0100 James Hogarth wrote:
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.
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.
On Wed, 18 May 2016 18:17:10 +0100 James Hogarth wrote:
Well if you're planning on doing a yum update anyway just cat rpmlist | xargs yum -y install
That wouldn't remove the unneeded packages on the second system.
On 05/18/2016 12:37 PM, Frank Cox wrote:
On Wed, 18 May 2016 18:17:10 +0100 James Hogarth wrote:
Well if you're planning on doing a yum update anyway just cat rpmlist | xargs yum -y install
That wouldn't remove the unneeded packages on the second system.
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 <to_remove> .. then yum install <to_add> 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.
Frank Cox wrote:
On Wed, 18 May 2016 09:30:54 +0100 James Hogarth wrote:
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.
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
On May 18, 2016, at 2:54 AM, Frank Cox theatre@melvilletheatre.com wrote:
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?
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
On May 18, 2016, at 1:02 PM, Noam Bernstein noam.bernstein@nrl.navy.mil wrote:
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).
I meant comm(1), by the way, although the other answers in this thread, especially the “yum shell” based ones, are cleaner.
Noam
On Wed, May 18, 2016 at 12:54:51AM -0600, Frank Cox wrote:
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?
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".
Jonathan Billings писал 2016-05-18 20:16:
On Wed, May 18, 2016 at 12:54:51AM -0600, Frank Cox wrote:
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?
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".
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.
On Wed, May 18, 2016 at 12:54:51AM -0600, Frank Cox wrote:
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?
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. :)
On Wed, 18 May 2016 13:32:36 -0400 Matthew Miller wrote:
( 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
This looks pretty much like what I had in mind.
Great! Thanks!
On Wed, May 18, 2016 at 11:39:10AM -0600, Frank Cox wrote:
( 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
This looks pretty much like what I had in mind. Great! Thanks!
Let me know if it works. :)
On 05/18/2016 12:32 PM, Matthew Miller wrote:
On Wed, May 18, 2016 at 12:54:51AM -0600, Frank Cox wrote:
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?
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.
Right .. if you are not at the same update levels then name.arch is better than full versions.
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.