Skip to content

Instantly share code, notes, and snippets.

@diversen
Last active April 5, 2022 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diversen/48f9965955797c3c3610342ce6d01069 to your computer and use it in GitHub Desktop.
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
<?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