Skip to content

Instantly share code, notes, and snippets.

@bezumkin
Last active February 7, 2023 06:05
Show Gist options
  • Save bezumkin/f36e5a7cccfea826642bea4779b8a9b3 to your computer and use it in GitHub Desktop.
Save bezumkin/f36e5a7cccfea826642bea4779b8a9b3 to your computer and use it in GitHub Desktop.
Download and upload MODX database from/to remote server
<?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__);
<?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