Daddou
Daddou

Reputation: 379

Keep files generated by RPM after rerunning rpm -e

Is it possible to keep RPM content in the filesystem after the uninstallation ?

Basically, I don't want to erase the files generated by the RPM when someone runs rpm -e, but still remove the package from the list of installed RPMs. I want to uninstall my application manually from the server and I cannot find a way to do so.

Thanks in advance.

Upvotes: 2

Views: 5040

Answers (3)

Rich
Rich

Reputation: 390

Specfile creation

From this perspective as a package creator, you can flag files as configurations. John Warbrick at Cambridge Uni has a good rundown of the different file markings you can use in an RPM specfile and how they behave during upgrade.

Files marked %config, if changed, are:

  • left behind on uninstall but renamed with an .rpmsave extension
  • untouched on update or reinstall, but the payload copy is installed with an .rpmnew extension

Warbrick does not deal with straight package removal: if a file marked %config is unchanged, erasing the package will remove the file. (Bear in mind that, according to RPM scriptlet ordering, RPM update or reinstall begins with erasing the old package, before the new files are lain down. I.e., the old unchanged config is replaced with the new config.)

It would be an abuse of RPM file classification to mark something a %config that is not really a config. This is important because sysadmins need to be able to trust the package payload. Plus, you probably don't want such a file to be renamed with an extension.

Your best hope then is to create the file during RPM %post. Files copied to the filesystem in %install are checked against the %files list and stored in the RPM database, but files created in %post are not. Again, this an abuse of the RPM spec file format, but if you mention it in the %description and any other documentation, but especially if it's logically expected behavior in the context of your package, you'll maybe get some sympathy.


Existing packages

For sysadmins wanting to remove a package without removing its payload, you use rpm --justdb. First, check the file list:

# rpm -ql $PACKAGE | tee $PACKAGE.payload
[rpm returns list of files, tee saves it in the file $PACKAGE.payload]

# rpm -e --justdb $PACKAGE

(At this stage, you may get a complaint about deps, so repeat with --nodeps if you must.)

And finally, check that the package is gone, but payload is still there:

# rpm -q $PACKAGE
package $PACKAGE is not installed
# ls -l $(<$PACKAGE.payload)
[ls queries list of files saved in $PACKAGE.payload]

(Or for a more reliable ls if filenames contain spaces, which would be unconscionable in RPM.)

# cat $PACKAGE.payload|xargs -d '\n' ls -l

Other observations

Note that for a package created using the method outlined at the top of my answer, attempting to list the files it owns with rpm -ql $PACKAGE will not show those persistent files. Another consequence of throwing down files during %post is that another package which "owns" those files could overwrite them unexpectedly - they're not listed in the RPM database, so they're not protected.

The two methods I've outlined break Best Practices for both RPM package creation and sysadmin. Please be very careful how you use this dangerous "little bit of knowledge". Maybe there's something else you could do to create the desired situation.

(Finally, I know this is a question from four year back. It wasn't answered. It needed answering. Cheers.)

Upvotes: 3

marcindulak
marcindulak

Reputation: 31

One of the advantages of RPMS is exactly that: you can uninstall (remove) all the files easily. If you want to install the files provided by an RPM manually, simply unpack the RPM as root, with:

cd / && rpm2cpio *.rpm | cpio -idmv

It's not a good idea, but you can unpack RPMS like that elsewhere (e.g. under ${HOME}), and that's very useful. You may need to adjust some environment variables though. You don't pollute the RPM database but still use the contents of an RPM. Of course your application may get broken by system updates, because it is not protected by dependencies. Anyway this is how you "install" and RPM if you are not root. Removal is also easy (if installation path chosen suitably).

Upvotes: 0

Aaron D. Marasco
Aaron D. Marasco

Reputation: 6758

rpm -e --repackage package_name will drop a re-installable copy in /var/spool/repackage. You can extract from that rpm using rpm2cpio if you need those files back individually.

Upvotes: 0

Related Questions