Last active
April 5, 2022 07:48
-
-
Save diversen/48f9965955797c3c3610342ce6d01069 to your computer and use it in GitHub Desktop.
Druapl 7 backup if you don't have SSH access but you can use mysqldump and tar
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 | |
/** | |
* Druapl 7 backup if you don't have SSH access but you can use mysqldump and tar | |
* Put this in the sites root folder and visit the script through a browser | |
* | |
* Fetch asdqwe-backup.sql from the server | |
* Fetch asdqwe-backup.tar.gz from the server | |
*/ | |
// Read database configuration | |
include_once "sites/default/settings.php"; | |
// Default database | |
$database = $databases['default']['default']; | |
$name = uniqid(); | |
// SQL dump | |
$mysql_dump_command = "mysqldump -p$database[password] --user=$database[username] --host=$database[host] --add-drop-table $database[database] > ./$name-backup.sql"; | |
exec($mysql_dump_command, $output, $ret_var); | |
if ($ret_var == 0) { | |
echo "Database dump created successfully<br />"; | |
} | |
// Source copy | |
$path = getcwd(); | |
$tar_create = "tar --exclude=$name-backup.tar.gz --exclude=sites/default/files* -czvf ./$name-backup.tar.gz . "; | |
exec($tar_create, $output, $ret_var); | |
if($ret_var == 0 || $ret_var == 1) { | |
echo "Backup created successfully<br />"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment