Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- containsElement () {
- local e
- for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
- return 1
- }
- PASSWORD=1
- HOST=localhost
- USER=root
- DATABASE=betweendigital
- DIR=dumps
- EXCLUDED_TABLES=(
- )
- CUTTED_TABLES=(
- stat_adnetworks
- stat_deals
- stat_deals_site_section
- stat_deals_traffic
- stat_eeni
- stat_fb
- stat_iow
- stat_iow_migrate
- stat_log
- stat_nac
- stat_rtb
- stat_subpub
- queue
- )
- IGNORED_TABLES_STRING=''
- for TABLE in "${EXCLUDED_TABLES[@]}"
- do :
- IGNORED_TABLES_STRING+=" --ignore-table=${DATABASE}.${TABLE}"
- done
- echo "Dump structure"
- mysqldump --host=${HOST} --user=${USER} --add-drop-database --password=${PASSWORD} --single-transaction --no-data ${DATABASE} >> $DIR/1_${DATABASE}.structure.sql
- echo "DUMP DATA"
- for t in $(mysql -NBA -h $HOST -u $USER --password=$PASSWORD -D $DATABASE -e 'show tables')
- do
- echo "DUMPING TABLE: $DATABASE.$t"
- if containsElement $t "${CUTTED_TABLES[@]}"
- then
- echo "THIS TABLE WILL BE CUTTED BY DATE"
- mysqldump --host=${HOST} --user=${USER} --password=${PASSWORD} --no-create-info --where "date >= '2016-11-01'" ${DATABASE} $t >> $DIR/${DATABASE}.${t}.cut.sql
- else
- echo "THIS TABLE WILL BE FULL"
- mysqldump -h ${HOST} -u $USER --password=$PASSWORD $DATABASE $t > $DIR/$DATABASE.$t.sql
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement