ss_blog_claim=88d0a386a6277415f42c9ee5561ded98

Archive for February 24th, 2007

How-To: Backup Your Wordpress Database

Introduction

Okay, so too often this happens to everyone. Here’s the scenario - You’re writing your brand new post, you’ve just published it and you’ve put hours of work into it and you’re proud of your efforts. An hour later your host/provider has a server fart and your database and all your hard work goes down the drain. Your instant reaction is most likely rage. Your first thought is most likely: “there goes all my hard work! I can’t be motivated to write it again, so I’ll just sit back and wait until the urge builds up to rewrite the post.” And to think all of this grief could be saved with 5 minutes work. Here’s a few methods how:

Method One - cPanel

If you happen to be using a host that has cPanel, you can find the script I have written below to be quite useful for backing up your Wordpress database (or any other database for that matter, which is why I love it because it is not restricted to Wordpress). Either select the code, copy + paste it into a new file and save it as anything you want, as long as the extension of the file is .php. Otherwise, click the link below the code box to download the PHP source file. Simply change the file extension to .php and save it.

<?php
#!/usr/local/bin/php -q 
 
 
function get_database_file($database_name, $domain, $username, $password)
{
        //Construct the URL out of all our little pieces
        $url = 'http://' . $username . ':' . $password .'@'.  $domain .'/getsqlbackup/'. $database_name .'.gz';
        //Return the file's contents
        return(file_get_contents($url));
}
 
function send_database_file($to, $from, $subject, $message)
{
        global $database_name, $domain, $username, $password;
        $unique_sep = md5(uniqid(time()));
        $headers .= "From: $from\\n".
        "MIME-Version: 1.0\\nContent-Type: multipart/mixed;boundary=\\"$unique_sep\\";\\n".
        "charset=\\"iso-8859-1\\"\\nContent-Transfer-Encoding: 7bit\\n\\n" .
        "--$unique_sep\\n".
        "Content-Type: text/plain; charset=\\"iso-8859-1\\"\\n".
        "Content-Transfer-Encoding: 7bit\\n\\n".
        $message."\\n\\n".
        "--$unique_sep\\n".
        "Content-Type: gz; name=\\"wp.gz\\"\\n".
        "Content-Transfer-Encoding: base64\\n".
        "Content-Disposition: attachment\\n\\n";
        $file = get_database_file($database_name, $domain, $username, $password);
        $headers .= chunk_split(base64_encode($file)) . "--$unique_sep--\\n";
        if(mail($to, $subject, $message, $headers))
        {
                return true;
        }
        else
        {
                return false;
        }
}
 
$database_name = "<Database name without cPanel username Prefix (eg: user_wrdp1 without user_)>";
$domain = "yourdomain:2082"; // Do not change the port number (:2082)
$username = "cpanel_username";
$password = "cpanel_password";
$to = "your.email@domain.com";
$from = "backups@domain.com";
 
send_database_file($to, $from, $database_name ." Database Backup", "The backup of ". $database_name ." was performed at ". date("g:i A F j, Y"));
 
?>
 

Download this code: backup-sql-wp.phps

SECURITY WARNING

Now using your favourite FTP client, upload your newly created file In the directory under public_html/ or www/. I emphasised that because it is absolutely critical that this is where you upload it, otherwise you will be left open to someone being able to download your database information. And now we’re ready to roll onto the next step..

Now presuming you’ve either created a new php file or downloaded the file and renamed it, you need to login to cPanel and find the Cron Jobs icon. If you’re having trouble finding it, reference findcron.jpg for help. Note that the image you say may differ to your cPanel interface. Once you have found it, click it (duh) and youll be greeted with two buttons: Standard or Advaned. For now, choose standard and you’ll be greeted with a few boxes and inputs. See croninput.jpg for an idea of what you need to put in all these boxes. The settings I have selected in this image are that my backup will be emailed to me every day at 3am (Server Time). If you would like to change this, simply do so by using the boxes. If you have trouble understanding what to do, don’t hesitate to leave a comment or email me using the email page.

Method Two - Wordpress Plugin

So there’s many great plugins out there for Wordpress which can do everything from add ajax goodness on pages to backup your database, which is exactly what we want. For this tutorial, I have used WP-DB-Backup which was originally developed by skippy.net but was since abandoned and taken up by Austin Matzko and has since been rereleased for WP 2.1. Simply head on over to the WP-DP-Backup page, download the plugin and read the simple installation instructions. I would repost the incstructions here, but you can simply view them after you click the link. I myself have not used this plugin, as I am a faithful user of the above mentioned Method One.

Method Three - Wordpress Internal Backup

As far as I can tell from reading and watching a short video, this method makes the above mentioned Method Two of using a plugin obsolete (although having not used the plugin myself, it may offer extra functionality that the Wordpress Backup Tool does not). To save me explaining this method, a video on TubeTutorial which can be viewed via this link explains the method in great detail.

Conclusion

So there’s three methods to hopefully save you some grief in the long run if you do happen to lose your database(s). Just a quick shout out to the guys and girls at TubeTutorial for the use of their video in Method Three which is part of their series: 7 Essential Wordpress Hacks. It’s well worth a look.

If you feel I have missed anything in this guide drop me a line in the comments or use this revolutionary new technology called Email and get in contact, stranger.

Thanks for reading!

Technorati Tags: , ,

If you liked this post, buy me a coffee!

A Talking Blog? Highly Unlikely..

Have you ever heard your blog whisper to you: “Use me to make money.” No? Me either.

So anyway, onto the real story…

A while ago I was broswing around one of the many CSS showcases on the internet and came across RockStartup. As you may or may not know, RockStartUp is a podcast about how PayPerpost, the blog marketing site started out and worked its way up to internatiol blogging fame. Now, this is a great tool for high traffic and low traffic bloggers alike. You simply write a blog post, wait for approval and then leave the post up for thirty (30) days and your payment will either be sent by cheque or paypal. I recently recieved my first few payments via Paypal and purchased myself a Killswitch Engage t-shirt. Sure, maybe if you decide to join you you’ll put your money to better use. You even have the option of donating the amount that you would earn for a post to Charity.

Also, PPP has also recently introduced their Segmentation System. It is used to award those bloggers out there whose blogs get those all important hits in large numbers. Sure we all wish we could recieve that high traffic. But for the lucky ones, you can go join PayPerPost and have a chance at getting $1,000 (no joke, I did say $1000) dollars just for a single post on your blog. So if you do happen to have a blog that meets the requirements set out for these high paying posts, I suggest that you visit PayPerPost now and signup before you miss out. Just a note on the side, all PayPerPost sponsored posts require that any sponsored post on your Blog must be disclosed as such (as I do in all my sponsored posts).

See, it’s the all important sponsored post badge! Bask in all it’s Glory.

If you liked this post, buy me a coffee!




February 2007
M T W T F S S
« Jan   Mar »
 1234
567891011
12131415161718
19202122232425
262728  

RSS  


Posts (RSS) Posts     Comments (RSS) Comments
 Add to Technorati Favorites


advertisements  






top commentators  


  • sexymonkey (2)
  • n0b (1)
  • L (1)
  • chanx (1)
  • june (1)