Created
March 19, 2014 14:24
-
-
Save borisguery/9642680 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
| #!/usr/bin/env bash | |
| # Because mysqlimport doesn't allow to append/prepend | |
| # custom statements and we need to disable the foreign | |
| # keys constraint which does not exist yet | |
| if [ "$#" -lt 2 ]; then | |
| printf "usage: %s database path_to_backup\n" $0 | |
| exit -1; | |
| fi | |
| DATABASE=$1; | |
| PATH_TO_BACKUP=$2 | |
| find . -name "*.txt" | sed -E -e 's/(\.\/|\.txt)//g' | sort | while read table; | |
| do echo "mysql $DATABASE -e \"\ | |
| SET FOREIGN_KEY_CHECKS=0; \ | |
| LOAD DATA INFILE '$PATH_TO_BACKUP/$table.txt' \ | |
| INTO TABLE $table;\ | |
| SET FOREIGN_KEY_CHECKS=1;\""; | |
| done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment