Last active
September 1, 2016 14:52
-
-
Save danny-englander/694f74d635b914f143706c861709cf68 to your computer and use it in GitHub Desktop.
An automated drush backup script with folder pruning using ZSH Globbing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/zsh | |
## An automated Drupal backup script using Drush and ZSH globbing. | |
## Ideally place this script in usr/local/bin | |
## Set this to run via a cronjob. | |
## Easy crontab setup: http://crontab-generator.org | |
## Inspiration from: by https://www.drupal.org/node/470114 | |
## by Danny Englander | dannyenglander.com | |
# Define System paths | |
PATH=/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin | |
# If using MAMP, Define MAMP paths, alter as needed for the specfic PHP version being used. | |
PATH=/Applications/MAMP/Library/bin/:$PATH | |
PATH=/Applications/MAMP/bin/php/php5.6.10/bin:$PATH | |
# Define the path to composer / drush | |
PATH="$HOME/.composer/vendor/bin:$PATH" | |
#======================================================================= | |
EXIT_SUCCESS=0 #Script errorlevel if it was executed without problems | |
#=========================================BACKUP BLOCK============================================ | |
# Drupal 8 site | |
drush -r /Users/myuser/Sites/myd8site --uri=http://d8.local cr | |
drush -r /Users/myuser/Sites/myd8site --uri=http://d8.local sql-dump --result-file --gzip | |
# Drupal 7 site | |
drush -r /Users/myuser/Sites/myd7site --uri=http://d7.local cc all | |
drush -r /Users/myuser/Sites/myd7site --uri=http://d7.local sql-dump --result-file --gzip | |
# ADD MORE SITES AS NEEDED BELOW IN THIS BLOCK. | |
#====================================END OF BACKUP BLOCK===================================== | |
#===================================BACKUP CONTROL BLOCK==================================== | |
## Loop to recursively check backup sub-directories and keep 14 newest in each | |
for d in /path/to/drush-backups/*; do | |
( cd $d && rm -rf ./*(Om[1,-15])) | |
done | |
#=================================END OF BACKUP COTROL BLOCK================================== | |
exit $EXIT_SUCCESS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment