diff --git a/restore-mysql-daily b/restore-mysql-daily index 9a7b3f0..8592268 100644 --- a/restore-mysql-daily +++ b/restore-mysql-daily @@ -21,7 +21,7 @@ FULLRESTORE=false SETPOSDB=db_for_master_log_position ### config file for mysql credentials -CFG='~/.my.cnf' +CFG='.my.cnf' ### dry-run will show actions for testing DRY_RUN=false @@ -103,7 +103,7 @@ while [[ $# -gt 0 ]]; do echo -e "\t-sk| --skip databases to not restore (e.g. mysql would replace users) [ array ] mysql" echo -e "\t -f| --full restore all tables not excluded (no comparison) [ array ] off" echo -e "\t -p| --pos datbase from which master log position will be used [ string ]" - echo -e "\t -c| --cfg path of config file for mysql credentials [ string ] ~/.my.cnf" + echo -e "\t -c| --cfg path of config file for mysql credentials [ string ] .my.cnf" echo -e "\t-ns| --nostart do not restart replication [ flag ] off" echo -e "\t-np| --noprompt do not prompt user (Y/n) [ flag ] off" echo -e "\t-mh| --masterhost replication master host address [ string ]" @@ -179,11 +179,16 @@ fi echo "\nfinding files in '$NEWPATH*.gz'" for FILE in $NEWPATH*.gz; do + if [[ "${SETPOSDB}" =~ ${FILE%%.*} ]]; then echo -e "\t-- recognized $FILE for master position and log file" + SETPOSFILE=$(realpath $FILE) + echo -e "\tposition file: $SETPOSFILE" + fi; + FILE=$(basename $FILE) STARTLOOP=$(date +%s) echo -e "\n$(date +%F\ %T) | $FILE:" - if [[ "${SETPOSDB}" =~ ${FILE%%.*} ]]; then echo -e "\t-- recognized $FILE for master position and log file";SETPOSFILE=$(realpath $FILE); fi; + if [[ "${SKIPDBS[*]}" =~ ${FILE%%.*} ]]; then echo -e "\t-- skipping $FILE";continue; fi; if [[ FULLRESTORE == false ]]; then @@ -208,14 +213,14 @@ for FILE in $NEWPATH*.gz; do printf '\t%02dh:%02dm:%02ds\n' $((EXCTIME/3600)) $((EXCTIME%3600/60)) $((EXCTIME%60)) done -if [[ MASTER_HOST && MASTER_USER && MASTER_PASSWORD ]]; then - echo "applying configuration for replication\n\thost: $MASTER_HOST\n\tuser: $MASTER_USER" +if [[ -n MASTER_HOST ]] && [[ -n MASTER_USER ]] && [[ -n MASTER_PASSWORD ]]; then + echo -e "applying configuration for replication\n\thost: $MASTER_HOST\n\tuser: $MASTER_USER" $CMD mysql -e "CHANGE MASTER TO master_host='$MASTER_HOST',master_user='$MASTER_USER',master_password='$MASTER_PASSWORD';" else echo "replication credentials not configured" fi -if [[ $SETPOSFILE ]]; then +if [[ -n $SETPOSFILE ]]; then SETPOSSTMT=$(zcat $SETPOSFILE | head -40 | grep MASTER | sed 's/-- //') echo -e "\n$SETPOSSTMT\n" $CMD mysql -e "$SETPOS"