Advertisement
zvinger

Untitled

Jan 19th, 2017
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. containsElement () {
  4.   local e
  5.   for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
  6.   return 1
  7. }
  8.  
  9. PASSWORD=1
  10. HOST=localhost
  11. USER=root
  12. DATABASE=betweendigital
  13. DIR=dumps
  14. EXCLUDED_TABLES=(
  15. )
  16. CUTTED_TABLES=(
  17. stat_adnetworks
  18. stat_deals
  19. stat_deals_site_section
  20. stat_deals_traffic
  21. stat_eeni
  22. stat_fb
  23. stat_iow
  24. stat_iow_migrate
  25. stat_log
  26. stat_nac
  27. stat_rtb
  28. stat_subpub
  29. queue
  30.     )
  31.  
  32. IGNORED_TABLES_STRING=''
  33. for TABLE in "${EXCLUDED_TABLES[@]}"
  34. do :
  35.    IGNORED_TABLES_STRING+=" --ignore-table=${DATABASE}.${TABLE}"
  36. done
  37.  
  38. echo "Dump structure"
  39. mysqldump --host=${HOST} --user=${USER} --add-drop-database --password=${PASSWORD} --single-transaction --no-data ${DATABASE} >> $DIR/1_${DATABASE}.structure.sql
  40. echo "DUMP DATA"
  41. for t in $(mysql -NBA -h $HOST -u $USER --password=$PASSWORD -D $DATABASE -e 'show tables')
  42. do
  43.     echo "DUMPING TABLE: $DATABASE.$t"
  44.     if containsElement $t "${CUTTED_TABLES[@]}"
  45.         then
  46.         echo "THIS TABLE WILL BE CUTTED BY DATE"
  47.         mysqldump --host=${HOST} --user=${USER} --password=${PASSWORD} --no-create-info --where "date >= '2016-11-01'" ${DATABASE} $t  >> $DIR/${DATABASE}.${t}.cut.sql
  48.     else
  49.         echo "THIS TABLE WILL BE FULL"
  50.         mysqldump -h ${HOST} -u $USER --password=$PASSWORD $DATABASE $t > $DIR/$DATABASE.$t.sql
  51.     fi
  52. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement