Skip to content

Instantly share code, notes, and snippets.

@init90
Created September 14, 2017 19:02
Show Gist options
  • Select an option

  • Save init90/5509b5ef6ed7406920abb5651052dc49 to your computer and use it in GitHub Desktop.

Select an option

Save init90/5509b5ef6ed7406920abb5651052dc49 to your computer and use it in GitHub Desktop.
Drupal 8 backup database from devel php
use Drupal\Core\Database\Database;
$connection_info = Database::getConnectionInfo('default');
$db = $connection_info['default']['database'];
$u = $connection_info['default']['username'];
$p = $connection_info['default']['password'];
$current_date = date('Y-m-d_H-i-s');
$command = "mysqldump --user=$u --password=$p $db";
$dump = shell_exec($command);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($db . '_' . $current_date . '.sql'));
echo $dump;
exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment