Skip to content

Instantly share code, notes, and snippets.

@brianberlin
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save brianberlin/e52f7380ba425ec7740b to your computer and use it in GitHub Desktop.

Select an option

Save brianberlin/e52f7380ba425ec7740b to your computer and use it in GitHub Desktop.
<?php
set_time_limit(0);
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
$version = $_GET['version'];
if ($version == '7') {
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} else if ($version == '6'){
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} else {
echo "NO_VERSION";
exit();
}
global $user;
$user = user_load(1);
$filename = 'backup-' . date('Y-m-d-G-i-s') . '.tar.bz2';
$cwd = getcwd();
$fullPath = $cwd . '/' . $filename;
if (!module_exists('backup_migrate')) {
echo "MISSING_BACKUP_MIGRATE";
exit();
}
require DRUPAL_ROOT . '/' . drupal_get_path('module', 'backup_migrate') . "/includes/profiles.inc";
require DRUPAL_ROOT . '/' . drupal_get_path('module', 'backup_migrate') . "/includes/destinations.inc";
backup_migrate_get_destination('db');
backup_migrate_get_destination('manual');
$settings = backup_migrate_get_profile('default');
$settings->destination_id = 'manual';
$settings->source_id = 'db';
$backup = backup_migrate_perform_backup($settings);
if ($version == '6')
$db_backup = $cwd . '/' . $settings->get_destination()->location . '/' . $backup->file_info['filename'] . '.' . implode('.', $backup->ext);
else
$db_backup = drupal_realpath($settings->get_destination()->location . '/' . $backup->file_info['filename'] . '.' . implode('.', $backup->ext));
exec("mv '$db_backup' '$cwd/'");
exec('tar -cjvf ' . $filename . ' --exclude=settings.php * .h* .g*');
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
header("Content-Type: application/octet-stream");
header("Content-Disposition: filename=\"$filename\"");
header("Content-length: $fsize");
header("Cache-control: private");
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
unlink($fullPath);
unlink($cwd . '/' . $backup->name . implode('.', $backup->ext));
fclose ($fd);
exit();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment