Advertisement
Guest User

Untitled

a guest
Oct 29th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/bin/sh
  2. #----------------------------------------------------
  3. # MySQL Database backup script; which the created file to an another server.
  4. # Created on: 28 Oct, 2016.
  5. # Version: 2
  6. #----------------------------------------------------
  7. FILE=my_db_file.sql.`date +"%Y%m%d"`
  8. # (1) set up all the mysqldump variables
  9. DBSERVER=db_host
  10. DATABASE=db_name
  11. USER=db_user
  12. PASS=db_password
  13. # (2) in case you run this more than once a day, remove the previous version of the file
  14. unalias rm 2> /dev/null
  15. rm ${FILE} 2> /dev/null
  16. rm ${FILE}.gz 2> /dev/null
  17. # (3) do the mysql database backup (dump)
  18. # use this command for a database server on a separate host:
  19. #mysqldump --opt --protocol=TCP --user=${USER} --password=${PASS} --host=${DBSERVER} ${DATABASE} > ${FILE}
  20. # use this command for a database server on localhost. add other options if need be.
  21. mysqldump --opt --user=${USER} --password=${PASS} ${DATABASE} > ${FILE}
  22. # (4) gzip the mysql database dump file
  23. gzip $FILE
  24. # (5) show the user the result
  25. echo "${FILE}.gz was created."
  26. #ls -l ${FILE}.gz
  27. #$ scp -r /var/www/db-backup/${FILE}.gz your_username@remotehost.edu:/some/remote/directory/bar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement