WordPress Backup Shell Script

For those seeking to backup their WordPress installations on a nightly basis, I have decided to publish the following shell script.

Below, any instance of a tilde [~] indicates /home/[username]/. Referencing to user root is key to this. You could change it to /home/[username]/ if you so chose.

#!/bin/csh -f

# Determine current date
setenv CURDATE date +%Y%m%d

# Backup all WP databases to compressed, dated file in home directory
mysqldump -q -e -hlocalhost -u[user] -p[pass] [database] | gzip - > ~/${CURDATE}_db-backup.sql.gz

# Backup WP files to compressed, dated file in home directory
cd ~/path/to/wp-files/
tar cf - . | gzip - > ~/${CURDATE}_files.tar.gz

Any data in [brackets] should be filled in, sans brackets.

This should sit in userroot, chmod’d to 755 to be executable.

You will get errors for all files in wp-uploads on the second TAR run for the backups. If you don’t want backups of your WP files but are more concerned about the backup of the database, remove everything from the last comment on down.

I personally get an email sent to me to verify that there were no errors in the running of the script. I also use FTP Voyager‘s scheduler to do a Move Down on the backups to a local machine. When I can get a RAID box running at home, I’ll be dumping it to that, since I trust RAID more than a single-point-of-failure HD machine. :)

15 thoughts on “WordPress Backup Shell Script

  1. Pingback: The Indiana Jones School of Management

  2. Pingback: Blogging Pro

  3. Pingback: Weblog Tools Collection » WP Backup Shell Script

  4. Pingback: skebrown » Blog Archive » Just Back Up WP

  5. I’m not much of a shell scripter, but I have been having problems getting this script to work. The first problem I was having was with the SETENV statement. I fixed this by changing it to:
    set CURDATE = `date +%y%m%d`

    My current problem has to do with ‘mysqldump’. I keep getting this error message:
    mysqldump: Got error: 1045: Access denied for user: ‘davescha_wrdp1@localhost’ (Using password: YES) when trying to connect

    I have everything correct, yet the thing keeps telling me that I can’t access the DB to back it up. I have tried several variations of what was in the script. They all report the same error.

    I can access the DB fine from phpMyAdmin and WP.

    Any thoughts?

  6. It seems to me that your host has disallowed you as a user to use mysqldump [assuming, of course, that you're being hosted ;) ]. That you had to change the environment doesn’t hugely surprise me; thanks for posting the SETENV statement that works for you.

    Sorry that it’s not working out for you. :(

    GFM

  7. Thank you, that was the question that I needed to help me figure out the mysqldump part. The user isn’t DB_USER, it’s ACCOUNT_USER! I kept putting in the username I used for the database. I thought I had actually tried that combo when I was trying to get it to work earlier. Oh well…

    I made the adjustment and now it’s working perfectly.

  8. Pingback: Weblog Tools Collection » WP Backup to Email Script

  9. Pingback: The Indiana Jones School of Management

  10. Pingback: Prashanth Rao’s Weblog » Blog Archive » Wordpress backup python script

  11. Pingback: codefuture.net thought repository

  12. Pingback: Shout Head :: How to setup multi-blogging with wordpress 2.0

  13. Pingback: Message in a bottle…. : Blog Archive : Script per fer una copia de seguretat diaria del WordPress

  14. Hi ,

    I am new to shell scripting but i am stuck with the following issue , as i want to catch a python script error and if there is an error then echo eyx message:
    the shell script i wrote is
    #!/bin/sh

    case “xyz” in
    get_xml)
    cd xyz
    python2.5 hello_xml.pyc;
    if [[ $? -ne "1" ]]; then
    echo “ERROR”
    exit
    else
    echo “Done”
    fi
    ;;

    but issue is even the python script hello_xml.pyc throws an error the shell IF statement is not catching it , it always echo “done” only!!! in both case of failure and success.
    Can some one point me to correct direction.

  15. Pingback: links for 2010-05-17 | Pratyush Kotturu - KE5YQZ

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>