Enter your email address:

Delivered by FeedBurner

How to backup mysql using php, and shell script - the easy way -


StumbleUpon Toolbar

As I was trying to find an easy way to backup a MySQL database with no ssh access to the server, there should be better ways, but i found this easy one.

You will need a Shell script, a .php script.

Ok, lets make this work

    First create a shell script with this line
    mysqldump --opt -u [user_name] -p [database_name] | gzip > [backup_file].dump.gz

    and name it, lets say:

    the_backup_script.sh

    Now create the .php script that will call the shell script.

    It will contain this:

    <?php
    echo exec('./the_back_script.sh');
    ?>

    and name it, for instance

    the_backup_php_script.php

Until this point this should work, just copy the two files using your ftp account in the root directory of your site.

Here comes the security issue, nobody wants that somebody discover this file and can get all you mysql database, so you have some options.

1. Create a complete server based security like shown here: http://www.pagetutor.com/keeper/http_authentication.html

2. Erase the files from your server once used, and upload them each time you may need to do a backup.

Trackback URL for this post:

http://www.go2linux.org/trackback/90
StumbleUpon Toolbar

 If you like this article, subscribe to our full rss

If this article was somehow useful for you, you can leave something in the tip's jar

Please post your question in our forum and use comments only to leave your comments about the article, thanks.

i found this very helpful.I

i found this very helpful.I am new to database especially in linux. I have a few queries
1.Can you tell me the maximum size of the table it can copy using this method.
2.Is there any other restrictions for this method.
3.How to restore the dumpfiles back to the database.

Thank in advance

with regards
Philip

Phil, first I have to tell

Phil, first I have to tell you that I am no expert with MySQL, but I will try to answer you questions the best I can.

1. I think there is no limit, just the MySQL Limit for a table, which I do not know.

2. I have not found any so far

3. You should create a script to restore, with this line in it.
mysql [database_name] < [backup_file].dump

Please read here.

Guillermo Garron

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Captcha
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

This site is proudly hosted at Bluefur Hosting