Backup MySql DB with PHP

  • cancer10
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Jun 29, 2006
  • Posts: 268
  • Status: Offline

Post December 12th, 2008, 4:09 am

Hi,

Is there any PHP script available that would take a complete backup of my database?

I have googled for this several times and everytime either I come up with a script that only takes data backup and not the db structure OR a script that uses mysqldump command (since my client is on a shared server, hence he is not authorized to run the execute command on his server),

So was wondering if there is a script that actually takes a complete backup of the db and not using the mysqldump command?


Thanx so much for your help.
Interview Questions & Answers - http://www.focusinterview.com
My Profile: http://outlineme.com/cancer10
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 12th, 2008, 4:09 am

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13458
  • Loc: Florida
  • Status: Offline

Post December 12th, 2008, 5:01 am

Is phpMyAdmin an option ?
Using the "Export" tab you can export table schemes and data.

If you've got something for data already and you don't mind taking a minute to parse some output from MySQL, you can use SHOW COLUMNS to get the table schema from the database.

Code: [ Select ]
mysql> help show columns
Name: 'SHOW COLUMNS'
Description:
Syntax:
SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name]
    [LIKE 'pattern' | WHERE expr]
 
SHOW COLUMNS displays information about the columns in a given table.
It also works for views as of MySQL 5.0.1. The LIKE clause, if present,
indicates which column names to match. The WHERE clause can be given to
select rows using more general conditions, as discussed in
http://dev.mysql.com/doc/refman/5.0/en/ ... -show.html.
 
...
 
The FULL keyword causes the output to include the privileges you have
as well as any per-column comments for each column.
 
...
 
URL: http://dev.mysql.com/doc/refman/5.0/en/ ... lumns.html
  1. mysql> help show columns
  2. Name: 'SHOW COLUMNS'
  3. Description:
  4. Syntax:
  5. SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name]
  6.     [LIKE 'pattern' | WHERE expr]
  7.  
  8. SHOW COLUMNS displays information about the columns in a given table.
  9. It also works for views as of MySQL 5.0.1. The LIKE clause, if present,
  10. indicates which column names to match. The WHERE clause can be given to
  11. select rows using more general conditions, as discussed in
  12. http://dev.mysql.com/doc/refman/5.0/en/ ... -show.html.
  13.  
  14. ...
  15.  
  16. The FULL keyword causes the output to include the privileges you have
  17. as well as any per-column comments for each column.
  18.  
  19. ...
  20.  
  21. URL: http://dev.mysql.com/doc/refman/5.0/en/ ... lumns.html
Strong with this one, the sudo is.
  • cancer10
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Jun 29, 2006
  • Posts: 268
  • Status: Offline

Post December 12th, 2008, 5:03 am

Question:

Q1) Does phpmyadmin uses exec() command when you export backup?

Q2) My client has phpmyadmin running on his hosting account, does that mean he is allowed to use the exec() command?


Thanx
Interview Questions & Answers - http://www.focusinterview.com
My Profile: http://outlineme.com/cancer10
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13458
  • Loc: Florida
  • Status: Offline

Post December 12th, 2008, 5:07 am

Q1) I don't know and it would take me at least an hour to dig through the code to find out. I would bet against it doing so though.

Q2) Impossible to tell without an answer to Q1.

If it's already installed, I suggest trying out the export tab.

Attachments:
phpmyadmin.png
Strong with this one, the sudo is.
  • cancer10
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Jun 29, 2006
  • Posts: 268
  • Status: Offline

Post December 12th, 2008, 5:09 am

Hi

Thanx for ur reply.

The problem is that my client wants a db backup with just a simple click of a button. This is the reason I cannot have him do that under phpmyadmin


thanx
Interview Questions & Answers - http://www.focusinterview.com
My Profile: http://outlineme.com/cancer10
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13458
  • Loc: Florida
  • Status: Offline

Post December 12th, 2008, 5:12 am

Does this client have access to cron jobs/tabs ?

You should be able to setup automated backups using it and Mysqldump if they do.
Strong with this one, the sudo is.
  • cancer10
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Jun 29, 2006
  • Posts: 268
  • Status: Offline

Post December 12th, 2008, 5:15 am

Nope, its a shared host with limited features.
Interview Questions & Answers - http://www.focusinterview.com
My Profile: http://outlineme.com/cancer10
  • cancer10
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Jun 29, 2006
  • Posts: 268
  • Status: Offline

Post December 14th, 2008, 10:04 pm

Hey,

Apart from a FULL backup script, I also want a script that takes incremental backups. Any such available?


Sorry for asking too much :)
Interview Questions & Answers - http://www.focusinterview.com
My Profile: http://outlineme.com/cancer10
  • Truce
  • Guru
  • Guru
  • No Avatar
  • Joined: Apr 25, 2004
  • Posts: 1477
  • Loc: Washington DC
  • Status: Offline

Post December 15th, 2008, 8:28 am

cancer10 wrote:
Hey,

Apart from a FULL backup script, I also want a script that takes incremental backups. Any such available?


Sorry for asking too much :)


If he's your client, shouldn't YOU be doing the work that you billed him for?

To point you in the right direction:
  • Learn how to form proper MySQL queries and about how to retrieve the table structure from the database.
  • Dive into the code of phpMyAdmin and see how they're formatting the output/backup files.
  • Code something similar up to suit your needs.

Incremental backups? Are you sure you're not looking for automatic recurring backups? Incremental backups are going to leave your client with several files that all have to be used to restore the database in case something goes wrong. That's not cool.

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 249 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.