|
|
|
@ -3,7 +3,7 @@
|
|
|
|
|
PROGNAME="dump-server-state"
|
|
|
|
|
REPOSITORY="https://gitea.evolix.org/evolix/dump-server-state"
|
|
|
|
|
|
|
|
|
|
VERSION="23.08"
|
|
|
|
|
VERSION="23.11"
|
|
|
|
|
readonly VERSION
|
|
|
|
|
|
|
|
|
|
dump_dir=
|
|
|
|
@ -64,14 +64,15 @@ Tasks options
|
|
|
|
|
--[no-]mount copy of mount points (default: yes)
|
|
|
|
|
--[no-]df copy of disk usage (default: yes)
|
|
|
|
|
--[no-]dmesg copy of dmesg (default: yes)
|
|
|
|
|
--[no-]mysql copy of mysql processes (default: yes)
|
|
|
|
|
--[no-]mysql-processes copy of mysql processes (default: yes)
|
|
|
|
|
--[no-]mysql-summary copy of mysql summary (default: yes)
|
|
|
|
|
--[no-]systemctl copy of systemd services states (default: yes)
|
|
|
|
|
|
|
|
|
|
Tasks options order matters. They are evaluated from left to right.
|
|
|
|
|
Examples :
|
|
|
|
|
* "[…] --none --uname" will do only the uname task
|
|
|
|
|
* "[…] --all --no-etc" will do everything but the etc task
|
|
|
|
|
* "[…] --etc --none --mysql" will do only the mysql task
|
|
|
|
|
* "[…] --etc --none --mysql-summary" will do only the mysql task
|
|
|
|
|
END
|
|
|
|
|
}
|
|
|
|
|
debug() {
|
|
|
|
@ -102,7 +103,7 @@ task_etc() {
|
|
|
|
|
rsync_bin=$(command -v rsync)
|
|
|
|
|
|
|
|
|
|
if [ -n "${rsync_bin}" ]; then
|
|
|
|
|
last_result=$(${rsync_bin} -ah --itemize-changes --exclude=.git /etc "${dump_dir}/")
|
|
|
|
|
last_result=$(${rsync_bin} -ah --itemize-changes --exclude=.git --delete /etc "${dump_dir}/")
|
|
|
|
|
last_rc=$?
|
|
|
|
|
|
|
|
|
|
if [ ${last_rc} -eq 0 ]; then
|
|
|
|
@ -186,11 +187,13 @@ task_dpkg_full() {
|
|
|
|
|
apt_config_bin=$(command -v apt-config)
|
|
|
|
|
|
|
|
|
|
if [ -n "${apt_config_bin}" ]; then
|
|
|
|
|
# will do something like `dir_state_status='/var/lib/dpkg/status'`
|
|
|
|
|
eval "$(${apt_config_bin} shell dir_state_status Dir::State::status)"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
dpkg_dir=$(dirname "${dir_state_status}")
|
|
|
|
|
|
|
|
|
|
if [ -d "${dpkg_dir}" ]; then
|
|
|
|
|
last_result=$(mkdir -p "${dump_dir}${dpkg_dir}" && chmod -R 755 "${dump_dir}${dpkg_dir}")
|
|
|
|
|
last_rc=$?
|
|
|
|
|
|
|
|
|
@ -229,6 +232,9 @@ task_dpkg_full() {
|
|
|
|
|
rc=10
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
debug "* ${dpkg_dir} not found"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
task_dpkg_status() {
|
|
|
|
@ -239,9 +245,11 @@ task_dpkg_status() {
|
|
|
|
|
apt_config_bin=$(command -v apt-config)
|
|
|
|
|
|
|
|
|
|
if [ -n "${apt_config_bin}" ]; then
|
|
|
|
|
# will do something like `dir_state_status='/var/lib/dpkg/status'`
|
|
|
|
|
eval "$(${apt_config_bin} shell dir_state_status Dir::State::status)"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -f "${dir_state_status}" ]; then
|
|
|
|
|
last_result=$(cp "${dir_state_status}" "${dump_dir}/dpkg-status.txt")
|
|
|
|
|
last_rc=$?
|
|
|
|
|
|
|
|
|
@ -252,6 +260,9 @@ task_dpkg_status() {
|
|
|
|
|
debug "${last_result}"
|
|
|
|
|
rc=10
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
debug "* ${dir_state_status} not found"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
task_packages() {
|
|
|
|
@ -741,6 +752,41 @@ task_mysql_processes() {
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
task_mysql_summary() {
|
|
|
|
|
debug "Task: MySQL summary"
|
|
|
|
|
|
|
|
|
|
mysqladmin_bin=$(command -v mysqladmin)
|
|
|
|
|
pt_mysql_summary_bin=$(command -v pt-mysql-summary)
|
|
|
|
|
|
|
|
|
|
if [ -n "${mysqladmin_bin}" ] && [ -n "${pt_mysql_summary_bin}" ]; then
|
|
|
|
|
# Look for local MySQL or MariaDB process
|
|
|
|
|
if pgrep mysqld > /dev/null || pgrep mariadbd > /dev/null; then
|
|
|
|
|
if ${mysqladmin_bin} ping > /dev/null 2>&1; then
|
|
|
|
|
# important to set sleep to 0
|
|
|
|
|
# because we don't want to block
|
|
|
|
|
# even if we lose some insight.
|
|
|
|
|
${pt_mysql_summary_bin} --sleep 0 > "${dump_dir}/mysql-summary.txt" 2> "${dump_dir}/mysql-summary.err"
|
|
|
|
|
last_rc=$?
|
|
|
|
|
|
|
|
|
|
if [ ${last_rc} -eq 0 ]; then
|
|
|
|
|
debug "* pt-mysql-summary OK"
|
|
|
|
|
else
|
|
|
|
|
debug "* pt-mysql-summary ERROR"
|
|
|
|
|
debug < "${dump_dir}/mysql-summary.err"
|
|
|
|
|
rm "${dump_dir}/mysql-summary.err"
|
|
|
|
|
rc=10
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
debug "* unable to ping with mysqladmin"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
debug "* no mysqld or mariadbd process is running"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
debug "* pt-mysql-summary not found"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
task_systemctl() {
|
|
|
|
|
debug "Task: Systemd services"
|
|
|
|
|
|
|
|
|
@ -841,6 +887,9 @@ main() {
|
|
|
|
|
if [ "${TASK_MYSQL_PROCESSES}" -eq 1 ]; then
|
|
|
|
|
task_mysql_processes
|
|
|
|
|
fi
|
|
|
|
|
if [ "${TASK_MYSQL_SUMMARY}" -eq 1 ]; then
|
|
|
|
|
task_mysql_summary
|
|
|
|
|
fi
|
|
|
|
|
if [ "${TASK_SYSTEMCTL}" -eq 1 ]; then
|
|
|
|
|
task_systemctl
|
|
|
|
|
fi
|
|
|
|
@ -950,6 +999,7 @@ while :; do
|
|
|
|
|
TASK_DF \
|
|
|
|
|
TASK_DMESG \
|
|
|
|
|
TASK_MYSQL_PROCESSES \
|
|
|
|
|
TASK_MYSQL_SUMMARY \
|
|
|
|
|
TASK_SYSTEMCTL
|
|
|
|
|
do
|
|
|
|
|
eval "${option}=1"
|
|
|
|
@ -978,6 +1028,7 @@ while :; do
|
|
|
|
|
TASK_DF \
|
|
|
|
|
TASK_DMESG \
|
|
|
|
|
TASK_MYSQL_PROCESSES \
|
|
|
|
|
TASK_MYSQL_SUMMARY \
|
|
|
|
|
TASK_SYSTEMCTL
|
|
|
|
|
do
|
|
|
|
|
eval "${option}=0"
|
|
|
|
@ -1124,6 +1175,13 @@ while :; do
|
|
|
|
|
TASK_MYSQL_PROCESSES=0
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
--mysql-summary)
|
|
|
|
|
TASK_MYSQL_SUMMARY=1
|
|
|
|
|
;;
|
|
|
|
|
--no-mysql-summary)
|
|
|
|
|
TASK_MYSQL_SUMMARY=0
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
--systemctl)
|
|
|
|
|
TASK_SYSTEMCTL=1
|
|
|
|
|
;;
|
|
|
|
@ -1173,6 +1231,7 @@ done
|
|
|
|
|
: "${TASK_DF:=1}"
|
|
|
|
|
: "${TASK_DMESG:=1}"
|
|
|
|
|
: "${TASK_MYSQL_PROCESSES:=1}"
|
|
|
|
|
: "${TASK_MYSQL_SUMMARY:=1}"
|
|
|
|
|
: "${TASK_SYSTEMCTL:=1}"
|
|
|
|
|
|
|
|
|
|
export LC_ALL=C
|
|
|
|
|