Skip to content

mysql_backup.sh

  1. #!/bin/bash
  2. prefixe=backup
  3. suffixe=$(date +%Y%m%d)
  4. filename=$prefixe$suffixe.sql
  5. host=host
  6. database=database
  7. user=user
  8. characterSet=UTF8
  9. mysqldump –skip-comments \
  10. –complete-insert \
  11. –default-character-set=$characterSet \
  12. –no-create-info \
  13. –skip-add-locks \
  14. –skip-opt \
  15. –host $host \
  16. –user $user \
  17. -p $database > $filename
  18. sed -i “1iuse $database;\nSET CHARACTER SET ‘$characterSet’;” $filename
  19. exit 0