Guest User

Untitled

a guest
Oct 7th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #!/bin/bash
  2. # Use credentials in /etc/mysql/debian.cnf to export MySQL database
  3.  
  4. database="$1"
  5. shift
  6. options="$@"
  7.  
  8. if [[ -z "$database" ]]; then
  9. echo "Usage: $0 database [options]" >&2
  10. exit 2
  11. fi
  12.  
  13. user=$(sudo grep user /etc/mysql/debian.cnf | head -n1 | sed -r 's/^.+=\s*//')
  14. pass=$(sudo grep password /etc/mysql/debian.cnf | head -n1 | sed -r 's/^.+=\s*//')
  15. socket=$(sudo grep socket /etc/mysql/debian.cnf | head -n1 | sed -r 's/^.+=\s*//')
  16.  
  17. mysqldump \
  18. --user="$user" \
  19. --password="$pass" \
  20. --socket="$socket" \
  21. --add-drop-table \
  22. --add-locks \
  23. --comments \
  24. --create-options \
  25. --disable-keys \
  26. --dump-date \
  27. --extended-insert \
  28. --no-create-db \
  29. --lock-tables \
  30. --set-charset \
  31. --quick \
  32. --routines \
  33. --events \
  34. --triggers \
  35. $options \
  36. $database
Add Comment
Please, Sign In to add comment