Very straightforward script to dump a MySQL database and import it back; locally f.i.
Database backup and import scripts.
DB_Dump.phpfrom your production site and obtain your .sql.gz compressed backup
- Save the backup file onto your localhost development site
DB_Import.phpfrom there and your database will now contains a copy of your production site.
Table of Contents
- Get a copy of
MySQLDump.phpscripts and store them in your production site (best, in a protected folder; f.i. with a
.htpasswd). The two files should be stored in the same folder.
DB_Dump.phpand adjust the five constants you will see at the beginning of the file: a password that the user needs to know before running the file and the database credentials (server, name, login & password).
- Get a copy of
MySQLImport.phpscripts and store them in your localhost development site. The two files should be stored in the same folder.
DB_Import.phpand adjust the five constants you will see at the beginning of the file: a password that the user needs to know before running the file and the database credentials (server, name, login & password).
Tip: you can use https://www.avonture.be/php_password/ for easily get the hash for the password of your choice.
Don't forget to secure the folder where you'll store
DB_Dump.php script on your production server. Make sure that no-one can access to that folder except you since backup files will be stored there. Think to a
.htaccess protection using an IP protection for instance.
Make a backup
Go to your production site and access to URL to the
DB_Dump.php script. If correctly initialized, the backup will be started and you'll get an hyperlink to the backup file once the process is done.
Click on the hyperlink to download a copy of the backup file and copy that file in your localhost development folder; where you've save the
Restore the backup
Go to your localhost site and access to URL to the
DB_Import.php script. If correctly initialized, you'll get a screen with the list of all backup files found, the most recent file first. Just click on the desired file and the importation will start..
MySQLImport classes are part of the
[MySQL Dump Utility](https://github.com/dg/MySQL-dump) of David Grudl