Last active
October 10, 2015 07:27
-
-
Save and1truong/3654728 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Ref: http://drush.ws/examples/example.drushrc.php | |
| # Ref: http://books.tag1consulting.com/scalability/drupal/start/backups | |
| echo 'Including config file…' | |
| if [ -f ./.config ]; then | |
| . ./.config | |
| fi | |
| echo 'Getting database connection settings…' | |
| CMD='foreach ($GLOBALS['"'"'databases'"'"']['"'"'default'"'"'] as $key => $info)'; | |
| CMD=$CMD' $dbs[] = "{$info['"'"'driver'"'"']}://{$info['"'"'username'"'"']}:{$info['"'"'password'"'"']}@{$info['"'"'host'"'"']}/{$info['"'"'database'"'"']}";' | |
| CMD=$CMD' print implode(" ", $dbs);' | |
| DBS=`drush eval "$CMD"` | |
| for DB in $DBS | |
| do | |
| NAME=${DB#*@} | |
| NAME=${NAME#*/} | |
| echo 'Getting table lists for table {'$NAME'}…' | |
| TABLES=`drush sql-query 'SHOW TABLES'` | |
| for TABLE in $TABLES | |
| do | |
| if [[ ! "$TABLE" =~ "cache_" && ! "$TABLE" =~ "Tables_in_" && ! "$TABLE" =~ "search_" && $TABLE != 'watchdog' && $TABLE != "history" ]] | |
| then | |
| LIST[${#LIST[@]}]=$TABLE | |
| fi | |
| done | |
| LIST=$(printf ",%s" "${LIST[@]}") | |
| LIST=${LIST:1} | |
| FILE=$BACKUP_DB_DIR'/'$NAME'.sql' | |
| drush sql-dump --db-url=$DB --tables-list=$LIST > $FILE | |
| # TODO: Git commit | |
| done |
This file contains hidden or 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
| read -p "Are you sure? " -n 1 | |
| if [[ ! $REPLY =~ ^[Yy]$ ]] | |
| then | |
| exit 1 | |
| fi |
This file contains hidden or 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
| LIST=(a b c) | |
| LIST=$(printf ",%s" "${LIST[@]}") | |
| LIST=${LIST:1} |
This file contains hidden or 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
| DB='mysql://user:pass@host/db:port' | |
| NAME=${DB#*@} | |
| NAME=${NAME#*/} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment