Guest User

Untitled

a guest
Oct 28th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # this script will backup all MYSQL databases the specified user has access to
  4. # - possibility to specify excluded tables so your backups will stay compact (defaults for TYPO3)
  5. # - backups can be removed after a custom-defined time
  6. #
  7. # modify these parameters:
  8.  
  9. DEST="/home/<user>/mySQLBackups" # backup destination directory
  10.  
  11. MyUSER="<username>" # MySQL username ------ FOR SECURITY REASONS THIS USER SHOULD HAVE READ-ONLY ACCESS to all DBs! ----
  12. MyPASS="<password>" # MySQL password
  13. MyHOST="<db-host>" # DB hostname
  14.  
  15. MAXAGE=60 # max AGE in DAYS for backup-files
  16.  
  17. EXCLUDED_TABLES=(
  18. be_sessions
  19. cache_treelist
  20. cf_cache_hash
  21. cf_cache_hash_tags
  22. cf_cache_imagesizes
  23. cf_cache_imagesizes_tags
  24. cf_cache_pages
  25. cf_cache_pagesection
  26. cf_cache_pagesection_tags
  27. cf_cache_pages_tags
  28. cf_cache_rootline
  29. cf_cache_rootline_tags
  30. cf_extbase_datamapfactory_datamap
  31. cf_extbase_datamapfactory_datamap_tags
  32. cf_extbase_object
  33. cf_extbase_object_tags
  34. cf_extbase_reflection
  35. cf_extbase_reflection_tags
  36. cf_static_file_cache
  37. cf_static_file_cache_tags
  38. cf_tx_cal_cache
  39. cf_tx_cal_cache_tags
  40. fe_session_data
  41. fe_sessions
  42. tx_extensionmanager_domain_model_extension
  43. )
  44.  
  45. #### DO NOT MODIFY BEYOND THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING! ###
  46. ############################################################################
  47.  
  48. # directory where backups will be stored:
  49. MBD="$DEST"
  50.  
  51. # get hostname:
  52. HOST="$(hostname)"
  53.  
  54. # file for current db backup file:
  55. FILE=""
  56.  
  57. # list of databases:
  58. DBS=""
  59.  
  60. # DO NOT BACKUP these databases:
  61. SKIPSCHEMES="information_schema performance_schema"
  62.  
  63. [ ! -d $MBD ] && mkdir -p $MBD || :
  64.  
  65.  
  66. # Get all database list first
  67. DBS="$(/usr/local/bin/mysql -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')"
  68.  
  69. for db in $DBS
  70. do
  71.  
  72. # build the ignored-tables string:
  73. IGNORED_TABLES_STRING=''
  74. for TABLE in "${EXCLUDED_TABLES[@]}"
  75. do
  76. IGNORED_TABLES_STRING+=" --ignore-table=${db}.${TABLE}"
  77. done
  78.  
  79. # date in dd-mm-yyyy format:
  80. NOW="$(date +"%Y-%m-%d-%H%M")"
  81.  
  82. skipdb=-1
  83. if [ "$SKIPSCHEMES" != "" ];
  84. then
  85. for i in $SKIPSCHEMES
  86. do
  87. [ "$db" == "$i" ] && skipdb=1 || :
  88. done
  89. fi
  90.  
  91. if [ "$skipdb" == "-1" ] ; then
  92. FILE="$MBD/$NOW-$db.sql.gz"
  93. # connect to mysql using mysqldump for current mysql database
  94. # pipe it out to gz file in backup dir
  95. /usr/local/bin/mysqldump -u $MyUSER -h $MyHOST -p$MyPASS --single-transaction --quick --skip-lock-tables --max_allowed_packet=512M $db ${IGNORED_TABLES_STRING} | gzip -9 > $FILE
  96. fi
  97. done
  98.  
  99.  
  100. # remove backups older than X days:
  101. find $MBD -mtime +$MAXAGE -exec rm '{}' \;
Add Comment
Please, Sign In to add comment