For those of you running WordPress on your own server, or a server that you maintain, I wrote a little script that may make upgrading your WordPress a bit easier. For me, I am running 4 installations of WordPress, so, when the upgrades are released, it's a bit of a pain to get them all into shape. So, thanks to Christer for the idea, I wrote a script that takes care of the job 10 times faster than if I were to do it by hand.
First, I should mention that this script comes with no warranty what-so-ever. Use it at your own risk. If you foul up your database or WordPress install, don't come crying to me. Although this upgraded my 4 installations without hitch, this does not necessarily mean that it will work for you. Please use caution when upgrading the files and the database. If you do run into problems, I will try to provide necessary support as possible. However, I am very busy, so it may be faster for you to figure out what happened, and to fix it on your own. You'll learn better that way anyway.
Next, this script follows the detailed instructions as closely as possible. Namely:
- Your existing WordPress install is backed up, just in case.
- All databases are backed up.
- All necessary and important files (.htaccess, wp-config, etc) and directories are backed up.
- The latest release is downloaded.
- All files are upgraded.
Of course, it is your job to navigate your browser to the appropriate PHP upgrade page for every WordPress installation that is upgraded, and verify that all plugins, permalinks and themes work.
At any rate, here is the code: a simple Bash script. The version of the script is 0.1.2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #!/bin/bash # This program upgrades your existing Wordpress installations that you are running on your server. # # You need to make the necessary adjustments to this script as needed for your situation. # # Make this script executable: 'chmod 777 wp_upgrade.sh' # Run the script: './wp_upgrade.sh' # # Author: Aaron Toponce # License: GPL v2 # Version: 0.1.2 # =================== Start of Script =================== # # Provide the necessary directories to what Wordpress installations need to be backed up space delimited # Change as necessary and uncomment # For example, if you had 3 sites in /var/www/site1, /var/www/site2 and /var/www/site3 # then it would look like below (do not add the trailing slash): # directories=(/var/www/site1 /var/www/site2 /var/www/site3) number=${#directories[@]} # Testing that all directories specified above are valid before beginning for (( i = 0 ; i < number ; i++ )); do if [[ ! -d ${directories[$i]} ]]; then echo "Directory ${$directories[$i]} does not exist." return 1 fi done # First, we need to get the necessary file cd ~ if [[ -f wordpress.tar.gz ]]; then echo "wordpress.tar.gz exists. Please take notice to this upgrade before continuing." return 1 fi wget -O latest.tar.gz http://wordpress.org/latest.tar.gz echo "First disable all plugins on all installations before continuing." echo "Press ENTER to continue..." read blah for (( i = 0 ; i < number ; i++ )); do clear cd ${directories[$i]} echo "We are backing up the full directory, in case anything goes wrong. Press ENTER..." read blah cd ../ tar -cvvf ${directories[$i]}.tar ${directories[$i]} gzip ${directories[$i]}.tar cd ${directories[$i]} mv ${directories[$i]}.tar.gz . # Timestamp in unix epoch format to create unique backup directories back_ts=$(date +%s) mkdir backup_${back_ts} # Backing up the necessary Wordpress database echo "Please provide the wordpress database name (case sensitive) for ${directories[$i]}:" read wp_db echo "And please provide the username to the database:" read wp_user mysqldump --add-drop-table -u ${wp_user} -p ${wp_db} > backup_${back_ts}/${wp_db}.sql # Make the necessary changes for what to backup. This is the default as provided by Wordpress. echo "Backing up the important files. Press ENTER..." read blah cp .htaccess wp-config.php backup_${back_ts} cp -r wp-content wp-images wp-includes/languages backup_${back_ts} # Time to copy the latest wordpress that we downloaded and overwrite all files echo "Getting the latest cp of wordpress. Press ENTER..." read blah cp ~/latest.tar.gz ./wordpress.tar.gz tar -zxvf wordpress.tar.gz # Overwrite all files echo "Overwriting all old Wordpress files with the new. Press ENTER..." read blah cd wordpress cp -rf * ../ # Copy the files that we backed up back echo "Coping the important backed up files back in. Press ENTER..." read blah cd ../backup_${back_ts} cp -rf * ../ echo "Point your browser to the necessary site and run the upgrade script." echo "EG: http://example.com/wp-admin/upgrade.php" echo "Update your permalinks and .htaccess." echo "Install updated plugins and themes" echo "Reactivate plugins" echo "Press ENTER to continue..." read blah done clear echo "Congratulations! You have successfully upgraded your Wordpress." echo "Please review that your browser resolves your site." echo "Enjoy!" |
{ 9 } Comments