Q:

RPM management challenges

We packaged up a RPM when our software was first deployed, we were very new to RPMs so we just defined all the files that need to be installed and it was done part of rpm install.
Fast forward 6 months later, we need to update this RPM. Here are the challenges we are facing:

rpm update will uninstall all the files of the previous RPM before installing new ones. Some of these files are configuration files, we would rather back them up first before uninstalling it
We didn't have %preun and %postun defined in the first RPM

After googling around, the only idea we have is to write a dummy RPM that requires the version of the first RPM. The dummy RPM will simply backup the files. We will them uninstall the first RPM and install the new RPM, which %preun and %postun are defined. 
I'm curious if there better ways to do this? Our application environment is sure to evolve and I would like to hear opinions from other professionals on this.

A:

If your only concern is not to lose your configuration files, you just need to add a %config(noreplace) mark for your configuration files. This will have the following effects (for those configuration files only):

on-disk file untouched --> file from update
on-disk file edited --> this file is kept, if rpm provides a new version; this one is saved as file.rpmnew

If you want to play around more with scriptlets (using %pre; %preun etc), take a look at this documenation.
If think that removes your need for %preun and %postun sections...

