Last active
February 7, 2023 06:05
-
-
Save bezumkin/f36e5a7cccfea826642bea4779b8a9b3 to your computer and use it in GitHub Desktop.
Download and upload MODX database from/to remote server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'config.core.php'; | |
require MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php'; | |
$filename = $dbase . '-' . date('Y-m-d') . '.sql.gz'; | |
header('Content-Type: application/x-gzip'); | |
header('Content-Disposition: attachment; filename="' . $filename . '"'); | |
$cmd = "mysqldump -h'$database_server' -u'$database_user' -p'$database_password' $dbase \ | |
--skip-lock-tables --add-drop-table --skip-comments --force --single-transaction --quick --no-tablespaces \ | |
| gzip --best"; | |
passthru($cmd); | |
unlink(__FILE__); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'config.core.php'; | |
require MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php'; | |
$filename = dirname(__FILE__) . '/' . $dbase . '.sql.gz'; | |
if (!file_exists($filename)) { | |
exit("Could not load $filename"); | |
} | |
$cmd = "gunzip -c $filename | mysql -h'$database_server' -u'$database_user' -p'$database_password' $dbase"; | |
passthru($cmd); | |
unlink($filename); | |
unlink(__FILE__); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment