Created
May 30, 2012 15:59
-
-
Save oxyc/2837210 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
| #!/bin/bash | |
| get_value() { drush core-status --pipe --show-passwords "$1"; } | |
| e_arrow() { echo -e " \033[1;33m➜\033[0m $@"; } | |
| host="$@" | |
| read -d '' dump_cmd <<'EOF' | |
| tmp_file="sql_transfer_db_dump.sql.tar.gz" | |
| if [ ! -f $tmp_file ]; then | |
| cd public_html 2>/dev/null || cd httpdoc 2>/dev/null | |
| get_value() { drush core-status --pipe --show-passwords "$1" 2>/dev/null; } | |
| mysqldump -u$(get_value database_username) \ | |
| -p$(get_value database_password) \ | |
| $(get_value database_name) \ | |
| | gzip --rsyncable > ../$tmp_file | |
| fi | |
| EOF | |
| e_arrow "Dumping database on remote host..." | |
| ssh $host "$dump_cmd" | |
| e_arrow "Transfering dump to localhost..." | |
| for ((i=1; i<4; i++)); do | |
| rsync --partial --progress --timeout=30 --rsh=ssh --archive $host:sql_transfer_db_dump.sql.tar.gz . | |
| if [[ $? -ne 0 ]]; then | |
| echo "Transfer complete" | |
| break | |
| else | |
| echo "Attempt ${i} failed. Trying again" | |
| fi | |
| done | |
| if [ $i -gt 3 ]; then | |
| echo "Transfer failed. Exiting..." | |
| exit 0 | |
| fi | |
| gunzip < sql_transfer_db_dump.sql.tar.gz \ | |
| | mysql -u$(get_value "database_username") \ | |
| -p$(get_value "database_password") \ | |
| $(get_value "database_name") | |
| e_arrow "Cleaning up..." | |
| ssh $host "rm sql_transfer_db_dump.sql.tar.gz" | |
| rm sql_transfer_db_dump.sql.tar.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment