Skip to content

Instantly share code, notes, and snippets.

@oksana-c
Created December 2, 2017 17:28
Show Gist options
  • Save oksana-c/ff37782216faf577d2b6e64b07775342 to your computer and use it in GitHub Desktop.
Save oksana-c/ff37782216faf577d2b6e64b07775342 to your computer and use it in GitHub Desktop.
Automated Drupal DB Pull from the server with Drush sql-dump
#!/usr/bin/env bash
# This script can be run from any location.
# - sh automated_dbpull.sh
# SSH to the server using SSH key.
ssh -tt -i ~/.ssh/id_rsa YOURUSERNAME@SERVER << EOF
cd /var/www/sites/SITEDIRECTORY/www;
drush sql-dump --result-file=../build/DBNAMEOFCHOICE.sql --gzip --structure-tables-key=cache,cache_*,history,search_*,sessions,watchdog;
exit;
EOF
echo "Exited SSH";
scp YOURUSERNAME@SERVER:/var/www/sites/SITEDIRECTORY/build/DBNAMEOFCHOICE.sql.gz ~/Sites/LOCALSITE/build/ref_db;
echo "DB downloaded."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment