Zend Framework Source Code Snippets

Generate MySQL DB Backup using config object

Bookmark and Share
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

croogie croogie
10 months ago

Quite good piece of code :-) Thanks for sharing

umpirsky umpirsky
8 months ago

Perfect!

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 bngsudheer
10 months ago
Edited:
bngsudheer bngsudheer
10 months ago
Revision Id:
127
Edit Message:
Initial Release
ZF Version
1.8.3
Tags:
MySQL Database Backup
Comments:
2
Views:
441
Points:
1 (1 votes)

History

r127

Initial Release

bngsudheer bngsudheer
10 months ago
diff
r126

Initial Release

bngsudheer bngsudheer
10 months ago