Generate MySQL DB Backup using config object
1 2 3 4 56 7 8 9 1011 12 13 | $config = Zend_Registry::get('config'); $dbUsername = $config->database->params->username; $dbPassword = $config->database->params->password; $dbName = $config->database->params->dbname; $file = APPLICATION_PATH . '/data/backup/' . time() . '.sql'; $command = sprintf(" mysqldump -u %s --password=%s -d %s --skip-no-data > %s", escapeshellcmd($dbUsername), escapeshellcmd($dbPassword), escapeshellcmd($dbName), escapeshellcmd($file) ); exec($command); |
Comments
You must login before commenting on a snippet. If you do not have an account, please register.
Snippet description
You have the database name, username and password in the config file, don't you?
Use the information to generate a MySQL dump file.
Snippet details
- Created:
-
bngsudheer
- Edited:
-
bngsudheer
- Revision Id:
- 127
- Edit Message:
- Initial Release
- ZF Version
- 1.8.3
- Tags:
- MySQL Database Backup
- Comments:
- 2
- Views:
- 441
- Points:
- 1 (1 votes)
10 months ago
Quite good piece of code :-) Thanks for sharing