rename backup-server-state to dump-server-state #150

Closed
gcolpart wants to merge 518 commits from unstable into rename-backup-server-state
5 changed files with 110 additions and 0 deletions
Showing only changes of commit 2493219270 - Show all commits

47
mysql/files/mysql_skip.sh Normal file
View file

@ -0,0 +1,47 @@
#!/bin/sh
# File containing error messages to skip (one per line).
error_messages="/etc/mysql_skip.conf"
# Sleep interval between 2 check.
sleep_interval="1"
# Exit when Seconds_Behind_Master reached 0.
exit_when_uptodate="false"
# Options to pass to mysql.
#mysql_opt="-P 3307"
# File to log skipped queries to (leave empty for no logs).
log_file="/var/log/mysql_skip.log"
mysql_skip_error() {
error="$1"
error="$(date --iso-8601=seconds) Skiping: $error"
printf "Skipping: $error\n"
mysql $mysql_opt -e 'SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;'
[ -n "$log_file" ] && echo "$error" >>"$log_file"
}
while true; do
slave_status="$(mysql $mysql_opt -e 'SHOW SLAVE STATUS\G')"
seconds_behind_master=$(echo "$slave_status" |grep 'Seconds_Behind_Master: ' |awk -F ' ' '{print $2}')
last_SQL_error="$(echo "$slave_status" |grep 'Last_SQL_Error: ' |sed 's/^.\+Last_SQL_Error: //')"
if [ "$seconds_behind_master" = "0" ]; then
#printf 'Replication is up to date!\n'
if [ "$exit_when_uptodate" = "true" ]; then
exit 0
fi
elif [ -z "$last_SQL_error" ]; then
sleep $sleep_interval
elif echo "$last_SQL_error" |grep -q -f $error_messages; then
mysql_skip_error "$last_SQL_error"
fi
sleep 1
done

View file

@ -45,3 +45,5 @@
- include_tasks: log2mail.yml
- include_tasks: utils.yml
- include_tasks: mysql_skip.yml

View file

@ -0,0 +1,44 @@
---
- name: "Copy script mysql_skip.sh into /usr/local/bin/"
copy:
src: mysql_skip.sh
dest: "/usr/local/bin/mysql_skip.sh"
owner: root
group: root
mode: "0700"
force: yes
tags:
- mysql_skip
- name: "Copy config file for mysql_skip.sh"
template:
src: mysql_skip.conf.j2
dest: "/etc/mysql_skip.conf"
owner: root
group: root
mode: "0600"
tags:
- mysql_skip
- name: "Create log file for mysql_skip.sh"
file:
path: "/var/log/mysql_skip.log"
state: touch
owner: root
group: adm
mode: "0640"
tags:
- mysql_skip
- name: "Copy mysql_skip.sh systemd unit"
template:
src: mysql_skip.systemd.j2
dest: /etc/systemd/system/mysql_skip.service
force: yes
- name: "Start or stop systemd unit"
systemd:
name: mysql_skip
daemon_reload: yes
state: "{{ mysql_skip_enabled | bool | ternary('started', 'stopped') }}"

View file

@ -0,0 +1 @@
## Put your matched patern here ##

View file

@ -0,0 +1,16 @@
[Unit]
Description=Script for skip define mysql replication errors
[Service]
ExecStart=/usr/local/bin/mysql_skip.sh
Type=simple
User=root
Group=root
PIDFile=/run/mysql_skip.pid
ExecStop=/bin/kill -- $MAINPID
KillMode=process
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target