Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # A shell script to backup a MySQL database locally.
  4. # Optionally uses SpiderOak to sync backups remotely.
  5. #
  6. # OPTIONAL SETUP
  7. # 1) Optional setup in order for user passwordless mysqldumps
  8. #
  9. # $ vim ~/.my.conf
  10. #
  11. # [mysqldump]
  12. # user=<DB_USER>
  13. # password=<DB_PASSWORD>
  14. #
  15. # $ chmod 0600 ~/.my.conf
  16. #
  17. # 2) Optional cron setup to run backup script daily at midnight
  18. #
  19. # $ crontab -e
  20. # 0 0 * * * sudo -u root sh -c "<SCRIPT_PATH>/mysql-backup.sh" >/dev/null 2>&1
  21.  
  22. # Database config
  23. db_name="<DB_NAME>"
  24. db_host="<DB_HOST>"
  25. db_user="<DB_USER>"
  26.  
  27. # Path to backup/sync directory
  28. path="/root/SpiderOak Hive/"
  29.  
  30. cd "${path}"
  31.  
  32. # Set the filename date prefix
  33. now=`date +"%Y-%m-%d"`
  34.  
  35. # Remove backup files older than 30 days
  36. find "${path}" -type f -name '*.sql' -mtime +30 -exec rm -f {} \;
  37.  
  38. # Exclude certain tables to save on filesize
  39. exclude=(
  40. <TABLE NAME>
  41. <TABLE NAME>
  42. <TABLE NAME>
  43. )
  44.  
  45. # Build the table ignore variable
  46. ignore=''
  47. for tbl in "${exclude[@]}"
  48. do :
  49. ignore+=" --ignore-table=${db_name}.${tbl}"
  50. done
  51.  
  52. # Backup database
  53. mysqldump -u ${db_user} -h ${db_host} ${ignore} ${db_name} > "${now}-${db_name}.sql"
  54.  
  55. # Securely sync to SpiderOak
  56. SpiderOakONE --batchmode
  57.  
  58. ls -la
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement