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!" |
{ 8 } Comments
I got one word for you…
w00t!
Simple and effective. My favorite.
Will start using it with the 10+ WP installations I have to keep up to date, and get you some good old feedback.
Great job!
I tested the script, really useful.
Some extra i added to it first:
echo the line with DB name, USER + PASS
it’s easier to copy+paste.
The second thing i’ll extend: if there’s no wp_images and so on, there souldn’t be any scary error messages from cp.
The biggest problem i had in upgrading, the “latest” 2.1.2 latest.tar.gz was a plain TAR, shame on wordpress.org
Greg
Awesome script. With over 30 WP installs, this makes the upgrade task look a lot more doable without Fantastico. Speaking of, it doesn’t seem that Fantastico disables plugins. If one blew up, wouldn’t it just be a case of restoring backups? Also, could you not use the wp-config.php file for input for database connection info? Just trying to make it that much easier! Thanks for sharing.
excelente script.
muchas gracias por tu aporte (:
Aaron,
Thank you for the script. I found some additional ways to automate the upgrade. Also, the script creates some security issues, as it keeps a tarball with a somewhat predicable name in the document root directory, so I moved the storage location for the backups outside of the document root.
The updated script can be found here: http://www.jerry-bell.com/2008/04/29/wordpress-backup-script/
I’m sure my code can be improved on – I’m not the worlds best coder, but I am pretty lazy and motivated to find ways to automate things.
Jerry
Hi!
Awesome script!
A few words of caution though to anyone that tries it. As previous user commented keeping backups in the wordpress directory poses quite a security risk as anyone can just download the tarball. Keep the backups in a directory that’s not accessible through the website.
A little modification to make life yet a bit easier:
Add a line below the directories array to handle the database names.
directories=(/home/dir1 /home/dir2 /home/dir3)
databasenames=(db1 db2 db3)
Then replace wp_db in the mysqldump connection strin g with ${databasenames[$i]}
Make sure the database names are in the same order as the directory. This can be done for the database users as well. I wouldn’t recommend keeping the passwords there though…
Good luck!
/Patrik
Для тех, кто мечтает о покупке недвижимости одним из лучших предложении будет недвижимость в Черногории. Это, во-первых, прекрасное вложение денежных средств, а, во-вторых, отличное место для сезонного отдыха. Для российского гражданина, желающего приобрести недвижимость в Черногории, власти препятствий не создают. При покупке недвижимости в Черногории вид на жительство предоставляется автоматически. Купить квартиру в Словении также очень легко. Одним из способов приобретения недвижимости в Словении является создание фирмы, с начальным капиталом около 10000 евро. Цены на недвижимость в Черногории и квартиры в Словении намного меньше, чем на побережье Черного моря – в Сочи или в Туапсе.
{ 6 } Trackbacks
[...] konusunda garanti vermiyorum. Database yedeinizi alp deneyebilirsiniz. Orjinal adres : Aaron Toponce Blog Archive Wordpress Upgrade Script Kod [...]
[...] to automagically upgrade your blog with minimal fuss, check out the script on Aaron’s blog: WordPress Upgrade Script. Worked like a charm for both the blogs I used it on, and I’ll definitely continue using it [...]
[...] just supports MySQL. Also, I would like to see some way to update my Wordpress installation without running a separate script to handle the upgrade. From what I understand, Movable Type supports this natively with CGI scripts [...]
[...] just supports MySQL. Also, I would like to see some way to update my Wordpress installation without running a separate script to handle the upgrade. From what I understand, Movable Type supports this natively with CGI scripts [...]
[...] just supports MySQL. Also, I would like to see some way to update my Wordpress installation without running a separate script to handle the upgrade. From what I understand, Movable Type supports this natively with CGI scripts [...]
[...] just supports MySQL. Also, I would like to see some way to update my Wordpress installation without running a separate script to handle the upgrade. From what I understand, Movable Type supports this natively with CGI scripts [...]
Post a Comment