Skip to content

Instantly share code, notes, and snippets.

@borisguery
Created March 19, 2014 14:24
Show Gist options
  • Select an option

  • Save borisguery/9642680 to your computer and use it in GitHub Desktop.

Select an option

Save borisguery/9642680 to your computer and use it in GitHub Desktop.
#!/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