Advertisement
Guest User

Untitled

a guest
May 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #!/bin/bash
  2. USAGE="\n\x1b[31mUsage:\x1b[0m extract_table_from_mysql_dump.sh my_table /path/to/dump.sql\n\x1b[32mOptional 3rd parameter:\x1b[0m /path/to/export/to\nThe export filename will default to extracted_{my_table}.sql\n"
  3.  
  4. if [[ -z "$1" ]] ; then
  5. printf "$USAGE"
  6. exit 1
  7. fi
  8. # Check the table name was provided
  9.  
  10. if [[ -z "$2" ]] ; then
  11. printf "$USAGE"
  12. exit 1
  13. fi
  14. # Check the input path to the dump was provided
  15.  
  16. if [[ -z "$3" ]] ; then
  17. OUTPUT="~/extracted_$1.sql"
  18. else
  19. OUTPUT="$3/extracted_$1.sql"
  20. fi
  21. # Check the output path to the dump was provided
  22. # If not, use a default one
  23.  
  24. sed -n -e "/DROP TABLE.*\`$1\`/,/UNLOCK TABLES/p" $2 > $OUTPUT
  25. # Run.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement