Skip to content

Instantly share code, notes, and snippets.

@chrisfree
Created February 11, 2016 17:41
Show Gist options
  • Save chrisfree/c0113dfae5f1958d42d2 to your computer and use it in GitHub Desktop.
Save chrisfree/c0113dfae5f1958d42d2 to your computer and use it in GitHub Desktop.
Backup a Drupal site to Amazon S3 using Drush
# Switch to the docroot.
cd /var/www/yourProject/docroot/
# Backup the database.
drush sql-dump --gzip --result-file=/home/yourJenkinsUser/db-backups/yourProject-`date +%F-%T`.sql.gz
# Switch to the backups directory.
cd /home/yourJenkinsUser/db-backups/
# Store the recently created db's filename as a variable.
database=$(ls -t | head -n1)
# Upload to Amazon S3, using s3cmd (https://github.com/s3tools/s3cmd).
s3cmd put $database s3://yourBucketName/$database
# Delete databases older than 10 days.
find /home/yourJenkinsUser/db-backups/ -mtime +10 -type f -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment