Wednesday, January 10, 2007

RPM Rollbacks

Ever afraid of updating packages or installing software on Linux? Those of us used to Windows would just go to "ADD/REMOVE" to remove a piece of software that you don't like. In OS X, you'd just simply drag things to trash.

However, what if you wanted to update your MySQL or PHP packages because there were new vulnerabilities or bugs discovered in your current version? Even if you had a development/test environment, it'd be nice to be able to go back to the previous version if the newly installed one breaks things or acts weird. Most Linux distros use Red Hat's RPM, and if you use RHEL or derivatives such as CentOS, you work with RPMs all the time. We can solve this issue with RPM rollbacks and transactions.

Let's say you're rolling out a new update for PHP, php-4.3.9, and you currently have php-4.3.8. You can install the new version and save the old package for rollback with the following command:

# rpm -Uvh --repackage php4.3.9
Preparing... ############################# [100%]
Repackaging...1:php ############################# [100%]
Upgrading...1:php ############################# [100%]

If you decide to erase an RPM, you can add the --repackage to your command andit'll save it:

# rpm -e --repackage

OK, now let's say this install of PHP broke things on your website, and for the timebeing you want to go back to the way things were. You can use the --rollback switchand specify a date or time. You can actually rollback to a target date, e.g.

# rpm -Uvh --rollback '5 minutes ago'
Rollback packages (+1/-1) to
Thu Jan 10 13:26:12 2007 (0x2f24d6f1):
Preparing... ########################### 100%]
1:php ########################### [ 33%]

BAM! Now you're back to where you were before. Now I know it's a hassle to rememberthe --rollback command every time, and if you forget, then you're kinda screwedbecause you don't have anything to go back to if needed. Therefore, you can edityour RPM macro file to use this option by default. Go ahead and find that file,usually located at /etc/rpm/macros. Add the line if it doesn't already exist:

%_repackage_all_erasures 1

You might also want to add the following in the macros file as well to put yourrollback repository of old RPMs into a specific directory or location:

%_repackage_dir /PATH/TO/LOCATION/

If you use up2date, you can add support for rollbacks by running up2date-config andthen clicking the "Retrieval/Installation" tab. There should be a checkbox nearthe bottom of the window that says "enable RPM rollbacks ...", and you can choosethe "Package storage directory" below that as well.

up2date might be deprecated now because a lot of people now use Yum as a convenientway to resolve dependencies, similar to Apt-get (but maybe not as good). You canautomatically support RPM rollbacks on all Yum updates if you add the following line to your Yumconfig file (usually /etc/yum.conf):

tsflags=repackage

Ok, that's all I have to say about that. RPM rollbacks can for the most part helpyou keep software up to date, and gives you an option to return to a previous statebefore installing these new packages if things go wrong.

No comments: