Last active
May 19, 2023 19:18
-
-
Save VirtuBox/71e60274393f1fabef2f42f5dd2de760 to your computer and use it in GitHub Desktop.
A simple php script to backup a database and getting db parameters from wp-config.php if available
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 | |
/** Define ABSPATH as this file's directory */ | |
if (! defined('ABSPATH')) { | |
define('ABSPATH', __DIR__ . '/'); | |
} | |
/* If wp-config.php exists in the WordPress root, or if it exists in the root and wp-settings.php | |
* doesn't, load wp-config.php. The secondary check for wp-settings.php has the added benefit | |
* of avoiding cases where the current directory is a nested installation, e.g. / is WordPress(a) | |
* and /blog/ is WordPress(b). | |
* | |
* If neither set of conditions is true, initiate loading the setup process. | |
*/ | |
if (file_exists(ABSPATH . 'wp-config.php')) { | |
require_once ABSPATH . 'wp-config.php'; | |
} elseif (@file_exists(dirname(ABSPATH) . '/wp-config.php') && ! @file_exists(dirname(ABSPATH) . '/wp-settings.php')) { | |
require_once dirname(ABSPATH) . '/wp-config.php'; | |
} else { | |
define('DB_NAME', ''); | |
define('DB_USER', ''); | |
define('DB_PASSWORD', ''); | |
define('DB_HOST', 'localhost'); | |
} | |
// Création de la sauvegarde dans un fichier zip | |
system(sprintf( | |
'mysqldump --no-tablespaces --opt -h%s -u%s -p"%s" %s | gzip > %s/dumpDB.sql.gz', | |
DB_HOST, | |
DB_USER, | |
DB_PASSWORD, | |
DB_NAME, | |
getenv('DOCUMENT_ROOT') | |
)); | |
echo '+DONE'; |
--no-tablespace needs to have an 's' added, --no-tablespaces. Otherwise, works beautifully. Thanks.
Thanks 👍
You are quite welcome! This little utility has already helped me quite a bit when I need to get a database dump when only ftp access is available.
--no-tablespace needs to have an 's' added, --no-tablespaces. Otherwise, works beautifully. Thanks.
Thanks 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
--no-tablespace needs to have an 's' added, --no-tablespaces. Otherwise, works beautifully. Thanks.