I keep all my WordPress projects in a Subversion repository. I also have a snapshot of unmodified ‘vanilla’ releases kept in the same repository.
Now theoretically I should simply be able to use the svn merge command in a working directory. But I have encountered serious problems, including file corruption warnings, when using svn merge in an actively developed working directory. Additionally, svn merge will delete files and directories that you added to the core WordPress install.
The method outlined here will be safe even if you have hacked core WordPress files, as long as you are very careful in constructing your rsync command.
- Import and tag the latest WordPress release into the repository
cd /tmp tar zxf /path/to/archive/wordpress-2.6.2.tar.gz OR unzip /path/to/archive/wordpress-2.6.2.zip svn import -m "Vanilla 2.6.2" wordpress file:///repository/wordpress/tags/2.6.2
- Remove the directory in /tmp
rm -rf /tmp/wordpress
- Check out a fresh copy of your WordPress project, and export a copy of the latest vanilla WordPress
cd /tmp svn co --ignore-externals file:///repository/wordpress/projects/myhappyblog svn export file:///repository/wordpress/tags/2.6.2 wordpress-2.6.2
- Do a dry run of rsync, starting with something like the following
rsync --dry-run -av --delete --svn-exclude --exclude '.svn/' --exclude favicon.ico wordpress-2.6.2/ myhappyblog/|less -SiX
- Now begins an iterative process – carefully examine the output from the above rsync dry run, paying special attention to files that will be deleted, since those will show you directories and files you have added. Add those directories or files as required using multiple ‘–exclude’ options. Here is an example from a recent upgrade I did:
rsync --dry-run -av --delete --svn-exclude --exclude '.svn/' --exclude favicon.ico --exclude 'images/' --exclude 'wp-content/plugins/podpress' --exclude 'wp-content/themes/sandbox' --exclude 'wp-content/uploads' wordpress-2.6.2/ myhappyblog/|less -SiX
- Once you are satisfied that you are not asking rsync to delete files and directories you need, run the command without ‘–dry-run’
rsync -av --delete --svn-exclude --exclude '.svn/' --exclude favicon.ico --exclude 'images/' --exclude 'wp-content/plugins/podpress' --exclude 'wp-content/themes/sandbox' --exclude 'wp-content/uploads' wordpress-2.6.2/ myhappyblog/
- Now change to your project working directory and look at the output of ‘svn stat’, here including sample output:
svn stat M wp-login.php M wp-includes/post.php M wp-includes/version.php M wp-includes/query.php M wp-includes/formatting.php M wp-includes/pluggable.php M wp-includes/widgets.php M wp-settings.php M wp-admin/includes/template.php M wp-admin/includes/image.php M wp-admin/import/textpattern.php M wp-admin/css/press-this-ie.css
- (conditional) In major upgrades, there will be WordPress core file deletions and additions. Handling these will require an extra couple commands, shown below. These commands are only necessary if there are additions and deletions.
# tell repository about deleted files that were removed by rsync svn remove --force `svn stat |egrep '^\!' | cut -d' ' -f2-999` # add new files to repository svn add `svn stat|egrep '^\?' | cut -d' ' -f2-999`
- You may choose to look through all the changes, or you may decide that the files that have been changed are safe (ie, unhacked WordPress core files).Now you are ready to commit the changes to the repository.
svn diff | less # optional svn commit -m "Upgraded to WordPress 2.6.2"
- At long last, you can go to the working directory where you are actively developing, and update that. Once you have tested thoroughly, you will be ready to update your live site (possibly with the same ‘svn update’ command).
cd /path/to/my/development/myhappyblog svn up
- Repeat from Step 3 for each of your SVN-managed WordPress projects!
- Drink. Pray that WordPress is not upgraded for at least another 6 months.