MySQL backups cpanel style
Hi there,
I've got a server online and I'd like to get daily mysql backups. I think that the way cpanel does those backups is great so I'll like to implement something like that, I've got full access to the server. So the way I use to do it with cpanel is just an wget of a web page like this and the sql file was created somehow in the background: http://www.server.com/getsqlbackup/database_name.sql.gz Should I do this with php ? |
The file .sql.gz suggests that a mysqldump was used to dump the full database contents in a .sql file, which was
subsequently compressed with gzip. Try looking up "mysqldump" to get started. A strategy could be to 1) run a cron job on the machine running mysql to dump the database to a file & compress it (as a "backup" of the database) 2) run a cron job on a second machine to copy the backup file to another machine for safe(r) keeping Step 2 can, but does not have to be, done by wget - which is used typically for web (HTTP) or FTP downloads. It depends on how your mysql machine is set up for remote access by the second machine - ie if it is configured for web access (apache), ftp access (vsftp), scp/sftp access (ssh), file sharing (nfs, samba)... |
Thanks for the reply timmeke :)
I know the basic use of mysqldump already :) The thing about the step 1 is that the file will be created and left somewhere. I want the backup to be created when I access the link, which I will download at the same time and will be deleted once the download finishes. I was thinking that it could even be some kind of pipe so the file would never end up being on the disk. Not sure if that's possible. I hope I explained myself but if not let me know and I'll do it with an example. |
Hey, I think I found a solution, still will have to make a few changes but I think this will work :)
http://stackoverflow.com/questions/4...p-or-otherwise |
Streaming it to the client browser. Could work out.
Mysql dump files are plain text, so an appropriate content-type (or -disposition) is in order. The only problem I may see is the size of the dump file. A -disposition ("save to disk") might be a good idea, to avoid the browser from trying to display the entire file (could be slow when you have several megabytes in size). |
Right now I'm using this two headers:
header('Content-Type: application/octet-stream'); header('Content-disposition: attachment; filename="file.qz"'); I did couple of tests and it works great :) |
All times are GMT -5. The time now is 06:57 AM. |