Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a PHP page to provide a complete MySQL DB Backup

Status
Not open for further replies.
May 22, 2002
63
GB
Hi,

Is there a simple way I can have a PHP page/Link automatically create a backup of a MySql DB when it is accessed?

I currently use PHPMYADMIN but would like to learn how this is done from scratch so I can put a small link in an online system I have written that allows Administrators to cbackup the DB in one click?

Thanks,

Anders2002
 
this may give you some pointers in the right direction

Hope this helps

t_avatar.jpg

'... and then it wouldn't compile?'
 
If you are the server administrator or have access to the mysql command line utilities you can use mysqldump.


You can write a short PHP script that invokes the command and then also zips/gzips/tars the output to conserve space.
 
OK, that sounds like a slightly better - if not more complicated solution (i guess??) But i could certainly use it compressing the dumps as they are going to take up a lot of space a simple text dump!

Do you know of any examples of where I can obtain a sample script that would export the DB, compress it and then spit it out to the browser as a downloadable link?
 
I've done that method suggested by DRJ478 before, but it isn't the most secure method available. If you plan on running it behind closed doors, then that will be a little better, but since you have to call the command command via exec() or system(), it is possible for someone to inject their own commands and do some damage to your server.
 
The best solution for using mysqldump is to setup a cron job on your server that does it.

This way there is:
1. No connection to the Web
2. It's done automatically and you don't have to worry
3. You can gzip/tar it automatically too.

If you write code that uses exec() or system() you have to write your code so that nobody can 'inject' their code. If there are no variables within that call there is no way for anyone to put any commands to the shell. All it does is trigger the dump.




 
Great, I will give that a try.

Many thanks for all your help!

Anders2002
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top