2022-11-04 13:53:47
This commit is contained in:
@@ -15,7 +15,6 @@ while [[ $# -gt 0 ]]; do
|
||||
-d|--dry-run)
|
||||
DRY_RUN=true
|
||||
CMD=echo
|
||||
$PIPE
|
||||
shift 1
|
||||
;;
|
||||
-a|--arch)
|
||||
@@ -42,11 +41,29 @@ while [[ $# -gt 0 ]]; do
|
||||
CFG=$2
|
||||
shift 2
|
||||
;;
|
||||
-n|--noprompt )
|
||||
-n|--noprompt)
|
||||
NOPROMPT=true
|
||||
shift 1
|
||||
;;
|
||||
*) echo 'error in command line parsing' >&2
|
||||
-h|--help)
|
||||
echo -e "\n\n\t______________________________ MySQL restoration script options ____________________________________\n"
|
||||
echo -e "\t | arg | | type | default |\n"
|
||||
echo -e "\t‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾"
|
||||
echo -e "\t-h| --help display this menu [ flag ]"
|
||||
echo -e "\t-d| --dry-run no permanent changes, show plan [ flag ]"
|
||||
echo -e "\t-a| --arch directory containing archive directories [ string ]"
|
||||
echo -e "\t-s| --subdir directory containing actual compressed sql files [ string ]"
|
||||
echo -e "\t-k| --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-n| --noprompt do not prompt user (Y/n) [ flag ] off"
|
||||
echo -e "\nEXAMPLE: $0 -p main_db -s backup_data -a /home/backups/mysql/daily -k 'mysql performance_stats' --dry-run"
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
echo 'error in command line parsing' >&2
|
||||
echo "try: '$0 --help"
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
@@ -66,11 +83,11 @@ echo -e "\tdry run = $DRY_RUN"
|
||||
echo -e "\n"
|
||||
|
||||
if [[ -f "$CFG" ]]; then
|
||||
if [[ ! $(grep user ~/.my.cnf) ]]; then
|
||||
if [[ ! $(grep user $CFG) ]]; then
|
||||
echo "ERROR: 'user' field not found in '$CFG'"
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! $(grep password ~/.my.cnf) ]]; then
|
||||
if [[ ! $(grep password $CFG) ]]; then
|
||||
echo "ERROR: 'password' field not found in '$CFG'"
|
||||
exit 1
|
||||
fi
|
||||
@@ -96,17 +113,18 @@ echo -e "\tstopping replication\n";
|
||||
$CMD mysql -e "STOP SLAVE;"
|
||||
|
||||
NEWDATE=$(ls -1r "$ARCHPATH" | head -1)
|
||||
NEWPATH="$ARCHPATH$NEWDATE$SUBDIR"
|
||||
NEWPATH="$ARCHPATH$NEWDATE/$SUBDIR"
|
||||
|
||||
if [[ $FULLRESTORE == false ]]; then
|
||||
OLDDATE=$(ls -1rt "$ARCHPATH" | head -1)
|
||||
OLDPATH="$ARCHPATH$OLDATE$SUBDIR"
|
||||
echo "compartive restoration selected: files from '$NEWDATE' will be compared to '$OLDDATE'"
|
||||
OLDPATH="$ARCHPATH$OLDDATE/$SUBDIR"
|
||||
echo "compartive restoration selected:\n\tfiles from:\t'$NEWDATE'\n\tcompared to:\t'$OLDDATE'"
|
||||
else
|
||||
echo "full restorion selected: comparisons will not be made, all non-excluded databases will be restored"
|
||||
fi
|
||||
|
||||
for FILE in $NEWPATH/*.gz; do
|
||||
echo "finding files '$NEWPATH*.gz'"
|
||||
for FILE in $NEWPATH*.gz; do
|
||||
FILE=$(basename $FILE)
|
||||
STARTLOOP=$(date +%s)
|
||||
echo -e "\n$(date +%F\ %T) | $FILE:"
|
||||
@@ -114,15 +132,16 @@ for FILE in $NEWPATH/*.gz; do
|
||||
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 [[ ! -z $OLDDATE ]]; then
|
||||
if [[ FULLRESTORE == false ]]; then
|
||||
OLDSIZE=$(stat -c %s $OLDPATH$FILE)
|
||||
else
|
||||
OLDSIZE=0
|
||||
fi
|
||||
|
||||
NEWSIZE=$(stat -c %s $NEWPATH/$FILE)
|
||||
NEWSIZE=$(stat -c %s $NEWPATH$FILE)
|
||||
|
||||
if [[ $OLDSIZE != $NEWSIZE ]]; then
|
||||
echo -e "\t$OLDDATE:$FILE:$OLDSIZE != $NEWDATE:$FILE:$NEWSIZE"
|
||||
DB=$(echo $FILE | cut -f1 -d'.')
|
||||
echo -e "\tDROPPING/CREATING '$DB'
|
||||
pv $NEWPATH$FILE | gunzip | mysql $DB"
|
||||
|
||||
Reference in New Issue
Block a user