Moving production database and files from AWS Drupal 8 instance to development server

You are here

Moving production database and files from AWS Drupal 8 instance to development server using SSH is really easy on EC2. The scripts below takes a copy of the production servers files directory and database in Drupal 8, the assest are then placed all into sync directory. Then SSH copies all these files to the development server. The process below allow no user to access production using Drush

#!/bin/sh
echo "Hello Backup drupal instance"

mysqldump --single-transaction -u username  -p  drupal_database_name > drupal_backup_file.sql
cp -vr /var/www/drupal_instance/sites/default/files  /home/admin/sync
scp  -i /home/admin/aws_file_access_to_dev.pem -r  ./*  admin@ipaddress_is_preferable_not_domain:/home/admin/backup

Now on the development server, this script restores the production database and files into the development build.

#!/bin/sh
echo "Hello restore the backups"
cp -vr /home/admin/backup/files /var/www/drupal_instance/sites/default
mysql  -u user -p -h localhost  drupal_database < /home/admin/backup/drupal_backup_file.sql

So that a local developer can then grab the latest copy of development add a drush alias like the example below in sites/default

 '/var/www/drupal_instance',
  'remote-host' => 'development_server.com',
  'remote-user' => 'ssh_user',
  'uri'  => 'default',
  'path-aliases' => array(
    '%drush' => '/home/admin/.composer/vendor/bin/drush',
    '%dump-dir'=> '/home/admin/.drush/drush_dump',
    '%files' => "/var/www/drupal_instance/sites/default/files"
  ),
  "command-specific" => array(
    'sql-sync' => array (
      'target-dump' => '/home/admin/.drush/drush_dump/drupal_backup_file.sql',
      'sanitize' => TRUE,
    ),
  ),
);

The issues I had with these scripts were the permission the following,

  • The bash script needs to be owned by www-data to access the files properly
  • The database permission for the need to be able to mysqldump and insert the backup file see here.

Of course, to move the code and the configuration about git needs to be installed on everything