Using the ports tree to install applications is one of the most common ways to install softare. However, what if you updated a port to the latest version and it turns out to break things? How do you downgrade to a previous version if your ports tree is up-to-date? This is where the portdowngrade utility comes in handy.
- Local root access on the box or be able to su to root.
- A SSH client such as puTTy or SecureCRT (if you are setting it up remotely).
- Ports! If you don’t have ports installed, you can install it with /stand/sysinstall
Installation is pretty straight forward with the configuration of a default cvs server.
# cd /usr/ports/sysutils/portdowngrade # make DEFAULT_CVS_SERVER="anoncvs@anoncvs1.FreeBSD.org:/home/ncvs" install clean
The way portdowngrade works is it logs into the default cvs server (or one that is defined with the -s flag) and processes the commit notes. It then displays the results of the previous versions for you to choose from and then updates the ports tree with that information (only for the selected port).
For this example, say you upgraded to php 5.2.0 and found that some of your php applications no longer work properly. Now you want to downgrade to the latest 5.1.x version. The first step is to tell portdowngrade(1) to pull the results for php5.
# portdowngrade lang/php5 portdowngrade 0.6 by Heiner Eichmann Please note, that nothing is changed in the ports tree unless it is explicitly permitted in step 6! Seeking port lang/php5 ... Found several matches: 1: lang/php5 2: lang/php5-extensions Please choose one: 1
Choose which port you want to downgrade. In this case, choose 1. Now it will log into the cvs server and present you with available versions to update the ports tree with.
Downgrading port: lang/php5 Step 1: Checking out port from CVS repository CVS root directory: anoncvs@anoncvs1.FreeBSD.org:/home/ncvs The authenticity of host 'anoncvs1.freebsd.org (18.104.22.168)' can't be established. DSA key fingerprint is 4d:59:19:7b:ea:9b:76:0b:ca:ee:da:26:e2:3a:83:b8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'anoncvs1.freebsd.org' (DSA) to the list of known hosts. Step 2: Reading the port history from the CVS repository Step 3: Analyzing the port history from the CVS repository Step 4: Load port version numbers and present results Keys:
: next page d : details p : previous page : leave presentation and downdgrade if wanted =============================================================================== number date portversion comment 1 2006/11/12 19:43:12 5.2.0 Update suhosin patch to 0.9.6.2 release. 2 2006/11/06 17:43:10 5.2.0 Update to 5.2.0 release. 3 2006/10/27 19:11:17 5.1.6 Update suhosin patch to 0.9.6 release. 4 2006/10/16 09:30:58 5.1.6 - fix open_basedir vulnerability in php4 and php5  5 2006/10/06 17:24:21 5.1.6 Enable suhosin patch by default. 6 2006/10/05 20:59:17 5.1.6 Added safety checks against integer overflow. 7 2006/09/29 19:11:40 5.1.6 Update suhosin patch to 0.9.5 release. 8 2006/09/10 16:37:43 5.1.6 Add support for QDBM. 9 2006/09/09 12:35:33 5.1.6 Update suhosin patch to 0.9.3 release. 10 2006/09/04 07:59:15 5.1.6 - Add experimental suhosin protection system support 11 2006/08/31 14:37:05 5.1.6 Update to 5.1.6 release. 12 2006/08/18 16:41:29 5.1.5 Update to 5.1.5. 13 2006/08/18 16:40:18 5.1.4 Allow php5-ldap to be built with SASL support enabled. 14 2006/07/11 13:21:54 5.1.4 Add databases/php5-oci8: 15 2006/05/23 06:19:19 5.1.4 Try to fix build on 4.X. 16 2006/05/18 22:17:32 5.1.4 - Holy Batman! Chase rerolled distfile. Only chance is an addition of a file 17 2006/05/10 14:46:43 5.1.4 Chase gmp library and bump PORTREVISION. Total lines: 152. Command:
Once you are prompted for a command, you can hit enter to choose which commit to downgrade to or you can hit space to view the next list of choices. Since 5.1.6 is in this first list we’ll hit enter.
You are now prompted to type the corresponding number to the version you want to be in the ports tree.
Enter version number to change port to (0: exit): 3
From here you will get to confirm your choice.
Step 5: Checking out choosen date of the port from the CVS repository Step 6: Modifying the port Port: lang/php5 at : 2006/10/27 19:11:17 Type 'yes' to bring the port to the state of the date above or 'no' to exit without changing anything. Note, that this only changes the port, not the installed software! yes or no:yes
Once you have confirmed, lang/php5 is now at version 5.1.6 and ready for you to actually downgrade your port. It is first recommended to run the following command to make sure we see the changes in the ports tree:
# portsdb -Uu
After that is complete, it’s time to downgrade the actual port. Since we are downgrading php5, we want to make sure all of the extensions are downgraded as well. For that we can use the wildcard *.
# portupgrade -f php5*
Once the portupgrade process finishes, your port is now downgraded. You can verify this with:
# pkg_info | grep php5