Screen Shot for Thumnbails


Conn Warwicker



Portfolio

Scripts and Websites I've made using PHP and MySQL mainly.

Snippets

Code snippets and mini tutorials

Contact

Contact me if you have any questions or queries



Home / Snippets / backup_mysql_database

This section is new and undergoing snippet addition, as of 13/6/11

Backup MySQL Database



A quick and simple way to back your MySQL database up and save it to a ZIP file.

<?php

$datestamp = date("Y-m-d");      
$filename = 'DB_'.$datestamp;

$command = "mysqldump -h localhost -u myDBuser --password=myDBpassword --all-databases | gzip > /path/to/backup/folder/$filename.sql.gz";

$result = passthru($command);
?>


Of course keeping the backup on the same server isn't good practice, so you may want to send it to a different server, or attach it to an email and send it to yourself (if it's a small DB).

But anyway, that's a very quick way of doing it if you were wondering.

Leave a Comment


Comment

All fields are required

Your Name


Your Email Address


Your Comment


Human Validation

What animal is this above:






Comments


No Comments Have Been Made