Advertisement
Guest User

Untitled

a guest
Oct 10th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Sets the script to exit when any error occurs
  4. set -e
  5.  
  6. lbackup_dir="/tmp"
  7. rbackup_dir="/home/${BKP_USER}/backup/"
  8.  
  9. # define backup filename using date-time based
  10. file_name="${MYSQL_DBNAME}-$(date +%d.%m.%Y-%H.%M)"
  11.  
  12. # Uses mysqldump to backup the database from MySQL server and redirecting
  13. # the output to backup file.
  14. # Chain the compression and removal of the original backup file in a single
  15. # command successful sequence of statements after the mysqldump
  16. echo "dumping database data and compressing..."
  17. mysqldump --host=${MYSQL_HOST} --user=${MYSQL_USER} --password=${MYSQL_PASSWD} ${MYSQL_DBNAME} > ${lbackup_dir}/${file_name}.sql \
  18. && tar -czf ${lbackup_dir}/${file_name}.tar.gz ${lbackup_dir}/${file_name}.sql \
  19. && rm -f ${lbackup_dir}/${file_name}.sql
  20. echo "dump and compression.... done"
  21.  
  22. # Waits 10 seconds do send over FTP after compression is finished
  23. sleep 10
  24.  
  25. # Sends the compressed backup to FTP server through SFTP
  26. # SFTP is slower, but has been more reliable in poor networks
  27. # Uses rsa key file for SSH authentication
  28. echo "sending backup over SFTP"
  29. sftp -i ${HOME}/.ssh/id_rsa ${BKP_USER}@${BKP_HOST}:${rbackup_dir} <<SCRIPT
  30. put ${lbackup_dir}/${file_name}.tar.gz ${file_name}.tar.gz
  31. SCRIPT
  32. echo "upload to SFTP.... done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement