Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
|
7ffca45354 | |
|
e95ecf1ae6 | |
|
9465efd217 | |
|
53e41977c8 | |
|
108e081464 | |
|
b1642d39cb | |
|
6daf5c6b42 | |
|
460be854b0 |
17
CHANGELOG
17
CHANGELOG
|
@ -14,28 +14,31 @@ The **patch** part changes is incremented if multiple releases happen the same m
|
|||
|
||||
### Changed
|
||||
|
||||
* ignore one of the errors in disklabel, bioctl and atactl due to incompatible disk types
|
||||
|
||||
### Fixed
|
||||
|
||||
### Removed
|
||||
|
||||
### Security
|
||||
|
||||
## [22.03.10] 2022-03-29
|
||||
## [23.06] 2023-06-05
|
||||
|
||||
### Changed
|
||||
|
||||
use nft is available and ignore iptables errors
|
||||
* command "rcctl ls failed" exits with 1 if enabled daemon is not running, but there is no error
|
||||
|
||||
## [22.03.9] 2022-03-27
|
||||
## [23.03] 2023-03-16
|
||||
|
||||
### Added
|
||||
|
||||
* `--all` and `--none` options to execute all of no task.
|
||||
* debug() accepts stdin
|
||||
|
||||
### Changed
|
||||
|
||||
* rename internal variables to use "task" as concept of unit of work
|
||||
* redirect disklabel, bioctl and atactl errors to stdin to be captured by $last_result
|
||||
* ignore one of the errors in bioctl and atactl due to incompatible disk types
|
||||
|
||||
## [22.03.8] 2022-03-27
|
||||
## [22.03] 2022-03-31
|
||||
|
||||
dump-server-state has its own repository and changelog
|
||||
Create an OpenBSD version of dump-server-state from the master debian version
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
PROGNAME="dump-server-state"
|
||||
REPOSITORY="https://gitea.evolix.org/evolix/dump-server-state"
|
||||
|
||||
VERSION="22.03.10"
|
||||
VERSION="23.06"
|
||||
readonly VERSION
|
||||
|
||||
dump_dir=
|
||||
|
@ -18,7 +18,8 @@ ${PROGNAME} version ${VERSION}
|
|||
Copyright 2018-2022 Evolix <info@evolix.fr>,
|
||||
Jérémy Lecour <jlecour@evolix.fr>,
|
||||
Éric Morino <emorino@evolix.fr>,
|
||||
Brice Waegeneire <bwaegeneire@evolix.fr>
|
||||
Brice Waegeneire <bwaegeneire@evolix.fr>,
|
||||
Jérémy Dubois <jdubois@evolix.fr>
|
||||
and others.
|
||||
|
||||
${REPOSITORY}
|
||||
|
@ -36,7 +37,6 @@ Usage: ${PROGNAME} --dump-dir=/path/to/dump/directory [OPTIONS]
|
|||
|
||||
Main options
|
||||
-d, --dump-dir path to the directory where data will be stored
|
||||
--backup-dir legacy option for dump directory
|
||||
-f, --force keep existing dump directory and its content
|
||||
-v, --verbose print details about each task
|
||||
-V, --version print version and exit
|
||||
|
@ -46,26 +46,19 @@ Tasks options
|
|||
--all reset options to execute all tasks
|
||||
--none reset options to execute no task
|
||||
--[no-]etc copy of /etc (default: no)
|
||||
--[no-]dpkg-full copy of /var/lib/dpkg (default: no)
|
||||
--[no-]dpkg-status copy of /var/lib/dpkg/status (default: yes)
|
||||
--[no-]apt-states copy of apt extended states (default: yes)
|
||||
--[no-]apt-config copy of apt configuration (default: yes)
|
||||
--[no-]packages copy of dpkg selections (default: yes)
|
||||
--[no-]processes copy of process list (default: yes)
|
||||
--[no-]packages copy of installed packages (default: yes)
|
||||
--[no-]uname copy of uname value (default: yes)
|
||||
--[no-]uptime copy of uptime value (default: yes)
|
||||
--[no-]netstat copy of netstat (default: yes)
|
||||
--[no-]processes copy of process list (default: yes)
|
||||
--[no-]fstat copy of network status (default: yes)
|
||||
--[no-]netcfg copy of network configuration (default: yes)
|
||||
--[no-]iptables copy of iptables (default: yes)
|
||||
--[no-]pfctl copy of PacketFilter values (default: yes)
|
||||
--[no-]sysctl copy of sysctl values (default: yes)
|
||||
--[no-]virsh copy of virsh list (default: yes)
|
||||
--[no-]lxc copy of lxc list (default: yes)
|
||||
--[no-]disks copy of MBR and partitions (default: yes)
|
||||
--[no-]disks copy of MBR, partitions and disks information (default: yes)
|
||||
--[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-]systemctl copy of systemd services states (default: yes)
|
||||
--[no-]rcctl copy of services states (default: yes)
|
||||
|
||||
Tasks options order matters. They are evaluated from left to right.
|
||||
Examples :
|
||||
|
@ -76,7 +69,8 @@ END
|
|||
}
|
||||
debug() {
|
||||
if [ "${VERBOSE}" = "1" ]; then
|
||||
echo "$1"
|
||||
msg="${1:-$(cat /dev/stdin)}"
|
||||
echo "${msg}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -126,151 +120,29 @@ task_etc() {
|
|||
fi
|
||||
}
|
||||
|
||||
task_apt_states() {
|
||||
apt_dir="/"
|
||||
apt_dir_state="var/lib/apt"
|
||||
apt_dir_state_extended_states="extended_states"
|
||||
|
||||
apt_config_bin=$(command -v apt-config)
|
||||
|
||||
if [ -n "${apt_config_bin}" ]; then
|
||||
eval "$(${apt_config_bin} shell apt_dir Dir)"
|
||||
eval "$(${apt_config_bin} shell apt_dir_state Dir::State)"
|
||||
eval "$(${apt_config_bin} shell apt_dir_state_extended_states Dir::State::extended_states)"
|
||||
fi
|
||||
extended_states="${apt_dir}/${apt_dir_state}/${apt_dir_state_extended_states}"
|
||||
|
||||
if [ -f "${extended_states}" ]; then
|
||||
debug "Task: APT states"
|
||||
|
||||
last_result=$(cp -r "${extended_states}" "${dump_dir}/apt-extended-states.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* cp OK"
|
||||
else
|
||||
debug "* cp ERROR :"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
task_apt_config() {
|
||||
debug "Task: APT config"
|
||||
|
||||
apt_config_bin=$(command -v apt-config)
|
||||
|
||||
if [ -n "${apt_config_bin}" ]; then
|
||||
last_result=$(${apt_config_bin} dump > "${dump_dir}/apt-config.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* apt-config OK"
|
||||
else
|
||||
debug "* apt-config ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* apt-config is not found"
|
||||
fi
|
||||
}
|
||||
|
||||
task_dpkg_full() {
|
||||
debug "Task: DPkg full state"
|
||||
|
||||
dir_state_status="/var/lib/dpkg/status"
|
||||
|
||||
apt_config_bin=$(command -v apt-config)
|
||||
|
||||
if [ -n "${apt_config_bin}" ]; then
|
||||
eval "$(${apt_config_bin} shell dir_state_status Dir::State::status)"
|
||||
fi
|
||||
|
||||
dpkg_dir=$(dirname "${dir_state_status}")
|
||||
|
||||
last_result=$(mkdir -p "${dump_dir}${dpkg_dir}" && chmod -R 755 "${dump_dir}${dpkg_dir}")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* mkdir/chmod OK"
|
||||
else
|
||||
debug "* mkdir/chmod ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
|
||||
rsync_bin=$(command -v rsync)
|
||||
|
||||
if [ -n "${rsync_bin}" ]; then
|
||||
last_result=$(${rsync_bin} -ah --itemize-changes --exclude='*-old' "${dpkg_dir}/" "${dump_dir}${dpkg_dir}/")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* rsync OK"
|
||||
else
|
||||
debug "* rsync ERROR :"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* rsync not found"
|
||||
|
||||
last_result=$(cp -r "${dpkg_dir}/*" "${dump_dir}${dpkg_dir}/" && rm -rf "${dump_dir}${dpkg_dir}/*-old")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* cp OK"
|
||||
else
|
||||
debug "* cp ERROR :"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
task_dpkg_status() {
|
||||
debug "Task: DPkg status"
|
||||
|
||||
dir_state_status="/var/lib/dpkg/status"
|
||||
|
||||
apt_config_bin=$(command -v apt-config)
|
||||
|
||||
if [ -n "${apt_config_bin}" ]; then
|
||||
eval "$(${apt_config_bin} shell dir_state_status Dir::State::status)"
|
||||
fi
|
||||
|
||||
last_result=$(cp "${dir_state_status}" "${dump_dir}/dpkg-status.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* cp OK"
|
||||
else
|
||||
debug "* cp ERROR :"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
}
|
||||
|
||||
task_packages() {
|
||||
debug "Task: List of installed package"
|
||||
debug "Task: List of installed packages"
|
||||
|
||||
dpkg_bin=$(command -v dpkg)
|
||||
last_result=$(pkg_info > "${dump_dir}/packages.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ -n "${dpkg_bin}" ]; then
|
||||
last_result=$(${dpkg_bin} --get-selections "*" > "${dump_dir}/current_packages.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* dpkg OK"
|
||||
else
|
||||
debug "* dpkg ERROR :"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* pkg_info OK"
|
||||
else
|
||||
debug "* dpkg not found"
|
||||
debug "* pkg_info ERROR :"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
|
||||
last_result=$(pkg_info -m > "${dump_dir}/packages_manual.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* pkg_info -m OK"
|
||||
else
|
||||
debug "* pkg_info -m ERROR :"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -307,7 +179,7 @@ task_uptime() {
|
|||
task_processes() {
|
||||
debug "Task: Process list"
|
||||
|
||||
last_result=$(ps fauxw > "${dump_dir}/ps.txt")
|
||||
last_result=$(ps auwwx > "${dump_dir}/ps.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
|
@ -321,7 +193,7 @@ task_processes() {
|
|||
pstree_bin=$(command -v pstree)
|
||||
|
||||
if [ -n "${pstree_bin}" ]; then
|
||||
last_result=$(${pstree_bin} -pan > "${dump_dir}/pstree.txt")
|
||||
last_result=$(${pstree_bin} -w > "${dump_dir}/pstree.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
|
@ -334,157 +206,59 @@ task_processes() {
|
|||
fi
|
||||
}
|
||||
|
||||
task_netstat() {
|
||||
task_fstat() {
|
||||
debug "Task: Network status"
|
||||
|
||||
ss_bin=$(command -v ss)
|
||||
last_result=$({ fstat | head -1 ; fstat | grep internet ; } > "${dump_dir}/fstat.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ -n "${ss_bin}" ]; then
|
||||
last_result=$(${ss_bin} -tanpul > "${dump_dir}/netstat-ss.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* ss OK"
|
||||
else
|
||||
debug "* ss ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* fstat OK"
|
||||
else
|
||||
debug "* ss not found"
|
||||
fi
|
||||
|
||||
netstat_bin=$(command -v netstat)
|
||||
|
||||
if [ -n "${netstat_bin}" ]; then
|
||||
last_result=$(netstat -laputen > "${dump_dir}/netstat-legacy.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* netstat OK"
|
||||
else
|
||||
debug "* netstat ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* netstat not found"
|
||||
debug "* fstat ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
}
|
||||
|
||||
task_netcfg() {
|
||||
debug "Task: Network configuration"
|
||||
|
||||
ip_bin=$(command -v ip)
|
||||
last_result=$(ifconfig -A > "${dump_dir}/ifconfig.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ -n "${ip_bin}" ]; then
|
||||
last_result=$(${ip_bin} address show > "${dump_dir}/ip-address.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* ip address OK"
|
||||
else
|
||||
debug "* ip address ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
|
||||
last_result=$(${ip_bin} route show > "${dump_dir}/ip-route.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* ip route OK"
|
||||
else
|
||||
debug "* ip route ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* ifconfig OK"
|
||||
else
|
||||
debug "* ip not found"
|
||||
debug "* ifconfig ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
|
||||
ifconfig_bin=$(command -v ifconfig)
|
||||
last_result=$(netstat -nr > "${dump_dir}/routes.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ -n "${ifconfig_bin}" ]; then
|
||||
last_result=$(${ifconfig_bin} > "${dump_dir}/ifconfig.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* ifconfig OK"
|
||||
else
|
||||
debug "* ifconfig ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* ifconfig not found"
|
||||
fi
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* netstat OK"
|
||||
else
|
||||
debug "* netstat ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
}
|
||||
|
||||
task_iptables() {
|
||||
debug "Task: iptables"
|
||||
task_pfctl() {
|
||||
debug "Task : PacketFilter"
|
||||
|
||||
iptables_bin=$(command -v iptables)
|
||||
last_result=$(pfctl -sa > "${dump_dir}/pfctl.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ -n "${iptables_bin}" ]; then
|
||||
last_result=$({ ${iptables_bin} -L -n -v; ${iptables_bin} -t filter -L -n -v; } > "${dump_dir}/iptables-v.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* iptables -v OK"
|
||||
else
|
||||
debug "* iptables -v ERROR"
|
||||
debug "${last_result}"
|
||||
# Ignore errors because we don't know if this is nft related or a real error
|
||||
# rc=10
|
||||
fi
|
||||
|
||||
last_result=$({ ${iptables_bin} -L -n; ${iptables_bin} -t filter -L -n; } > "${dump_dir}/iptables.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* iptables OK"
|
||||
else
|
||||
debug "* iptables ERROR"
|
||||
debug "${last_result}"
|
||||
# Ignore errors because we don't know if this is nft related or a real error
|
||||
# rc=10
|
||||
fi
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* pfctl OK"
|
||||
else
|
||||
debug "* iptables not found"
|
||||
fi
|
||||
|
||||
iptables_save_bin=$(command -v iptables-save)
|
||||
|
||||
if [ -n "${iptables_save_bin}" ]; then
|
||||
last_result=$(${iptables_save_bin} > "${dump_dir}/iptables-save.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* iptables-save OK"
|
||||
else
|
||||
debug "* iptables-save ERROR"
|
||||
debug "${last_result}"
|
||||
# Ignore errors because we don't know if this is nft related or a real error
|
||||
# rc=10
|
||||
fi
|
||||
else
|
||||
debug "* iptables-save not found"
|
||||
fi
|
||||
|
||||
nft_bin=$(command -v nft)
|
||||
|
||||
if [ -n "${nft_bin}" ]; then
|
||||
last_result=$(${nft_bin} list ruleset > "${dump_dir}/nft-ruleset.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* nft ruleset OK"
|
||||
else
|
||||
debug "* nft ruleset ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
debug "* pfctl ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -494,7 +268,7 @@ task_sysctl() {
|
|||
sysctl_bin=$(command -v sysctl)
|
||||
|
||||
if [ -n "${sysctl_bin}" ]; then
|
||||
last_result=$(${sysctl_bin} -a --ignore 2>/dev/null | sort -h > "${dump_dir}/sysctl.txt")
|
||||
last_result=$(${sysctl_bin} -a 2>/dev/null | sort -h > "${dump_dir}/sysctl.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
|
@ -509,106 +283,78 @@ task_sysctl() {
|
|||
fi
|
||||
}
|
||||
|
||||
task_virsh() {
|
||||
debug "Task: virsh list"
|
||||
|
||||
virsh_bin=$(command -v virsh)
|
||||
|
||||
if [ -n "${virsh_bin}" ]; then
|
||||
last_result=$(${virsh_bin} list --all > "${dump_dir}/virsh-list.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* virsh list OK"
|
||||
else
|
||||
debug "* virsh list ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* virsh not found"
|
||||
fi
|
||||
}
|
||||
|
||||
task_lxc() {
|
||||
debug "Task: lxc list"
|
||||
|
||||
lxc_ls_bin=$(command -v lxc-ls)
|
||||
|
||||
if [ -n "${lxc_ls_bin}" ]; then
|
||||
last_result=$(${lxc_ls_bin} --fancy > "${dump_dir}/lxc-list.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* lxc list OK"
|
||||
else
|
||||
debug "* lxc list ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* lxc-ls not found"
|
||||
fi
|
||||
}
|
||||
|
||||
task_disks() {
|
||||
debug "Task: Disks"
|
||||
|
||||
lsblk_bin=$(command -v lsblk)
|
||||
awk_bin=$(command -v awk)
|
||||
sysctl_bin=$(command -v sysctl)
|
||||
|
||||
if [ -n "${lsblk_bin}" ] && [ -n "${awk_bin}" ]; then
|
||||
disks=$(${lsblk_bin} -l | grep disk | grep -v -E '(drbd|fd[0-9]+)' | ${awk_bin} '{print $1}')
|
||||
if [ -n "${sysctl_bin}" ]; then
|
||||
disks=$(${sysctl_bin} hw.disknames | grep -Eo "(wd|sd)[0-9]*")
|
||||
for disk in ${disks}; do
|
||||
dd_bin=$(command -v dd)
|
||||
if [ -n "${dd_bin}" ]; then
|
||||
last_result=$(${dd_bin} if="/dev/${disk}" of="${dump_dir}/MBR-${disk}" bs=512 count=1 2>&1)
|
||||
disklabel_bin=$(command -v disklabel)
|
||||
if [ -n "${disklabel_bin}" ]; then
|
||||
last_result=$(${disklabel_bin} "${disk}" 2>&1 > "${dump_dir}/partitions-${disk}")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* dd ${disk} OK"
|
||||
if [ ${last_rc} -eq 0 ] || { [ ${last_rc} -ne 0 ] && [ "${last_result}" = "disklabel: DIOCGDINFO: Input/output error" ]; }; then
|
||||
debug "* disklabel ${disk} OK"
|
||||
else
|
||||
debug "* dd ${disk} ERROR"
|
||||
debug "* disklabel ${disk} ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* dd not found"
|
||||
debug "* disklabel not found"
|
||||
fi
|
||||
fdisk_bin=$(command -v fdisk)
|
||||
if [ -n "${fdisk_bin}" ]; then
|
||||
last_result=$(${fdisk_bin} -l "/dev/${disk}" > "${dump_dir}/partitions-${disk}" 2>&1)
|
||||
|
||||
bioctl_bin=$(command -v bioctl)
|
||||
if [ -n "${bioctl_bin}" ]; then
|
||||
last_result=$(${bioctl_bin} "${disk}" 2>&1 > "${dump_dir}/bioctl-${disk}")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* fdisk ${disk} OK"
|
||||
if [ ${last_rc} -eq 0 ] || { [ ${last_rc} -ne 0 ] && [ "${last_result}" = "bioctl: DIOCINQ: Inappropriate ioctl for device" ]; } || { [ ${last_rc} -ne 0 ] && [ "${last_result}" = "bioctl: BIOCINQ: Input/output error" ]; }; then
|
||||
debug "* bioctl ${disk} OK"
|
||||
else
|
||||
debug "* fdisk ${disk} ERROR"
|
||||
debug "* bioctl ${disk} ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* fdisk not found"
|
||||
debug "* bioctl not found"
|
||||
fi
|
||||
|
||||
atactl_bin=$(command -v atactl)
|
||||
if [ -n "${atactl_bin}" ]; then
|
||||
last_result=$(${atactl_bin} "${disk}" 2>&1 > "${dump_dir}/atactl-${disk}")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ] || { [ ${last_rc} -ne 0 ] && [ "${last_result}" = "atactl: ATA device returned error register 0" ]; } || { [ ${last_rc} -ne 0 ] && [ "${last_result}" = "atactl: ATAIOCCOMMAND failed: Input/output error" ]; }; then
|
||||
debug "* atactl ${disk} OK"
|
||||
else
|
||||
debug "* atactl ${disk} ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* atactl not found"
|
||||
fi
|
||||
|
||||
done
|
||||
cat "${dump_dir}"/partitions-* > "${dump_dir}/partitions"
|
||||
cat "${dump_dir}"/bioctl-* > "${dump_dir}/bioctl"
|
||||
cat "${dump_dir}"/atactl-* > "${dump_dir}/atactl"
|
||||
else
|
||||
if [ -n "${lsblk_bin}" ]; then
|
||||
debug "* lsblk not found"
|
||||
fi
|
||||
if [ -n "${awk_bin}" ]; then
|
||||
debug "* awk not found"
|
||||
fi
|
||||
debug "* sysctl not found"
|
||||
fi
|
||||
}
|
||||
|
||||
task_mount() {
|
||||
debug "Task: Mount points"
|
||||
|
||||
findmnt_bin=$(command -v findmnt)
|
||||
mount_bin=$(command -v mount)
|
||||
|
||||
if [ -n "${findmnt_bin}" ]; then
|
||||
last_result=$(${findmnt_bin} > "${dump_dir}/mount.txt")
|
||||
if [ -n "${mount_bin}" ]; then
|
||||
last_result=$(${mount_bin} > "${dump_dir}/mount.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
|
@ -619,24 +365,7 @@ task_mount() {
|
|||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* findmnt not found"
|
||||
|
||||
mount_bin=$(command -v mount)
|
||||
|
||||
if [ -n "${mount_bin}" ]; then
|
||||
last_result=$(${mount_bin} > "${dump_dir}/mount.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* mount points OK"
|
||||
else
|
||||
debug "* mount points ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* mount not found"
|
||||
fi
|
||||
debug "* mount not found"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -646,7 +375,7 @@ task_df() {
|
|||
df_bin=$(command -v df)
|
||||
|
||||
if [ -n "${df_bin}" ]; then
|
||||
last_result=$(${df_bin} --portability > "${dump_dir}/df.txt")
|
||||
last_result=$(${df_bin} > "${dump_dir}/df.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
|
@ -677,58 +406,68 @@ task_dmesg() {
|
|||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
|
||||
last_result=$(${dmesg_bin} -s > "${dump_dir}/dmesg-console.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* dmesg console buffer OK"
|
||||
else
|
||||
debug "* dmesg console buffer ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
|
||||
else
|
||||
debug "* dmesg not found"
|
||||
fi
|
||||
}
|
||||
|
||||
task_mysql_processes() {
|
||||
debug "Task: MySQL processes"
|
||||
task_rcctl() {
|
||||
debug "Task: Services"
|
||||
|
||||
mysqladmin_bin=$(command -v mysqladmin)
|
||||
rcctl_bin=$(command -v rcctl)
|
||||
|
||||
if [ -n "${mysqladmin_bin}" ]; then
|
||||
# Look for local MySQL or MariaDB process
|
||||
if pgrep mysqld > /dev/null || pgrep mariadbd > /dev/null; then
|
||||
last_result=$(${mysqladmin_bin} --verbose processlist > "${dump_dir}/mysql-processlist.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* mysqladmin OK"
|
||||
else
|
||||
debug "* mysqladmin ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
else
|
||||
debug "* no mysqld or mariadbd process is running"
|
||||
fi
|
||||
else
|
||||
debug "* mysqladmin not found"
|
||||
fi
|
||||
}
|
||||
|
||||
task_systemctl() {
|
||||
debug "Task: Systemd services"
|
||||
|
||||
systemctl_bin=$(command -v systemctl)
|
||||
|
||||
if [ -n "${systemctl_bin}" ]; then
|
||||
last_result=$(${systemctl_bin} --no-legend --state=failed --type=service > "${dump_dir}/systemctl-failed-services.txt")
|
||||
if [ -n "${rcctl_bin}" ]; then
|
||||
last_result=$(${rcctl_bin} ls failed > "${dump_dir}/rcctl-failed-services.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
if [ ${last_rc} -eq 0 ] || [ ${last_rc} -eq 1 ]; then
|
||||
debug "* failed services OK"
|
||||
else
|
||||
debug "* failed services ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
|
||||
last_result=$(${rcctl_bin} ls on > "${dump_dir}/rcctl-on-services.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* on services OK"
|
||||
else
|
||||
debug "* on services ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
|
||||
last_result=$(${rcctl_bin} ls started > "${dump_dir}/rcctl-started-services.txt")
|
||||
last_rc=$?
|
||||
|
||||
if [ ${last_rc} -eq 0 ]; then
|
||||
debug "* started services OK"
|
||||
else
|
||||
debug "* started services ERROR"
|
||||
debug "${last_result}"
|
||||
rc=10
|
||||
fi
|
||||
|
||||
else
|
||||
debug "* systemctl not found"
|
||||
debug "* rcctl not found"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
if [ -z "${dump_dir}" ]; then
|
||||
echo "ERROR: You must provide the --dump-dir argument" >&2
|
||||
|
@ -747,48 +486,30 @@ main() {
|
|||
if [ "${TASK_ETC}" -eq 1 ]; then
|
||||
task_etc
|
||||
fi
|
||||
if [ "${TASK_DPKG_FULL}" -eq 1 ]; then
|
||||
task_dpkg_full
|
||||
fi
|
||||
if [ "${TASK_DPKG_STATUS}" -eq 1 ]; then
|
||||
task_dpkg_status
|
||||
fi
|
||||
if [ "${TASK_APT_STATES}" -eq 1 ]; then
|
||||
task_apt_states
|
||||
fi
|
||||
if [ "${TASK_APT_CONFIG}" -eq 1 ]; then
|
||||
task_apt_config
|
||||
fi
|
||||
if [ "${TASK_PACKAGES}" -eq 1 ]; then
|
||||
task_packages
|
||||
fi
|
||||
if [ "${TASK_PROCESSES}" -eq 1 ]; then
|
||||
task_processes
|
||||
fi
|
||||
if [ "${TASK_UPTIME}" -eq 1 ]; then
|
||||
task_uptime
|
||||
fi
|
||||
if [ "${TASK_UNAME}" -eq 1 ]; then
|
||||
task_uname
|
||||
fi
|
||||
if [ "${TASK_NETSTAT}" -eq 1 ]; then
|
||||
task_netstat
|
||||
if [ "${TASK_UPTIME}" -eq 1 ]; then
|
||||
task_uptime
|
||||
fi
|
||||
if [ "${TASK_PROCESSES}" -eq 1 ]; then
|
||||
task_processes
|
||||
fi
|
||||
if [ "${TASK_FSTAT}" -eq 1 ]; then
|
||||
task_fstat
|
||||
fi
|
||||
if [ "${TASK_NETCFG}" -eq 1 ]; then
|
||||
task_netcfg
|
||||
fi
|
||||
if [ "${TASK_IPTABLES}" -eq 1 ]; then
|
||||
task_iptables
|
||||
if [ "${TASK_PFCTL}" -eq 1 ]; then
|
||||
task_pfctl
|
||||
fi
|
||||
if [ "${TASK_SYSCTL}" -eq 1 ]; then
|
||||
task_sysctl
|
||||
fi
|
||||
if [ "${TASK_VIRSH}" -eq 1 ]; then
|
||||
task_virsh
|
||||
fi
|
||||
if [ "${TASK_LXC}" -eq 1 ]; then
|
||||
task_lxc
|
||||
fi
|
||||
if [ "${TASK_DISKS}" -eq 1 ]; then
|
||||
task_disks
|
||||
fi
|
||||
|
@ -801,11 +522,8 @@ main() {
|
|||
if [ "${TASK_DMESG}" -eq 1 ]; then
|
||||
task_dmesg
|
||||
fi
|
||||
if [ "${TASK_MYSQL_PROCESSES}" -eq 1 ]; then
|
||||
task_mysql_processes
|
||||
fi
|
||||
if [ "${TASK_SYSTEMCTL}" -eq 1 ]; then
|
||||
task_systemctl
|
||||
if [ "${TASK_RCCTL}" -eq 1 ]; then
|
||||
task_rcctl
|
||||
fi
|
||||
|
||||
|
||||
|
@ -853,66 +571,22 @@ while :; do
|
|||
exit 1
|
||||
;;
|
||||
|
||||
--backup-dir)
|
||||
printf 'WARNING: "--backup-dir" is deprecated in favor of "--dump-dir".\n'
|
||||
if [ -n "${dump_dir}" ]; then
|
||||
debug "Dump directory is already set, let's ignore this one."
|
||||
else
|
||||
debug "Dump directory is not set already, let's stay backward compatible."
|
||||
# with value separated by space
|
||||
if [ -n "$2" ]; then
|
||||
dump_dir=$2
|
||||
shift
|
||||
else
|
||||
printf 'ERROR: "--backup-dir" requires a non-empty option argument.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
--backup-dir=?*)
|
||||
# with value speparated by =
|
||||
printf 'WARNING: "--backup-dir" is deprecated in favor of "--dump-dir".\n'
|
||||
if [ -n "${dump_dir}" ]; then
|
||||
debug "Dump directory is already set, let's ignore this one."
|
||||
else
|
||||
debug "Dump directory is not set already, let's stay backward compatible."
|
||||
dump_dir=${1#*=}
|
||||
fi
|
||||
;;
|
||||
--backup-dir=)
|
||||
# without value
|
||||
printf 'WARNING: "--backup-dir" is deprecated in favor of "--dump-dir".\n'
|
||||
if [ -n "${dump_dir}" ]; then
|
||||
debug "Dump directory is already set, let's ignore this one."
|
||||
else
|
||||
printf 'ERROR: "--backup-dir" requires a non-empty option argument.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
--all)
|
||||
for option in \
|
||||
TASK_ETC \
|
||||
TASK_DPKG_FULL \
|
||||
TASK_DPKG_STATUS \
|
||||
TASK_APT_STATES \
|
||||
TASK_APT_CONFIG \
|
||||
TASK_PACKAGES \
|
||||
TASK_PROCESSES \
|
||||
TASK_UNAME \
|
||||
TASK_UPTIME \
|
||||
TASK_NETSTAT \
|
||||
TASK_PROCESSES \
|
||||
TASK_FSTAT \
|
||||
TASK_NETCFG \
|
||||
TASK_IPTABLES \
|
||||
TASK_PFCTL \
|
||||
TASK_SYSCTL \
|
||||
TASK_VIRSH \
|
||||
TASK_LXC \
|
||||
TASK_DISKS \
|
||||
TASK_MOUNT \
|
||||
TASK_DF \
|
||||
TASK_DMESG \
|
||||
TASK_MYSQL_PROCESSES \
|
||||
TASK_SYSTEMCTL
|
||||
TASK_RCCTL
|
||||
do
|
||||
eval "${option}=1"
|
||||
done
|
||||
|
@ -921,26 +595,19 @@ while :; do
|
|||
--none)
|
||||
for option in \
|
||||
TASK_ETC \
|
||||
TASK_DPKG_FULL \
|
||||
TASK_DPKG_STATUS \
|
||||
TASK_APT_STATES \
|
||||
TASK_APT_CONFIG \
|
||||
TASK_PACKAGES \
|
||||
TASK_PROCESSES \
|
||||
TASK_UNAME \
|
||||
TASK_UPTIME \
|
||||
TASK_NETSTAT \
|
||||
TASK_PROCESSES \
|
||||
TASK_FSTAT \
|
||||
TASK_NETCFG \
|
||||
TASK_IPTABLES \
|
||||
TASK_PFCTL \
|
||||
TASK_SYSCTL \
|
||||
TASK_VIRSH \
|
||||
TASK_LXC \
|
||||
TASK_DISKS \
|
||||
TASK_MOUNT \
|
||||
TASK_DF \
|
||||
TASK_DMESG \
|
||||
TASK_MYSQL_PROCESSES \
|
||||
TASK_SYSTEMCTL
|
||||
TASK_RCCTL
|
||||
do
|
||||
eval "${option}=0"
|
||||
done
|
||||
|
@ -953,34 +620,6 @@ while :; do
|
|||
TASK_ETC=0
|
||||
;;
|
||||
|
||||
--dpkg-full)
|
||||
TASK_DPKG_FULL=1
|
||||
;;
|
||||
--no-dpkg-full)
|
||||
TASK_DPKG_FULL=0
|
||||
;;
|
||||
|
||||
--dpkg-status)
|
||||
TASK_DPKG_STATUS=1
|
||||
;;
|
||||
--no-dpkg-status)
|
||||
TASK_DPKG_STATUS=0
|
||||
;;
|
||||
|
||||
--apt-states)
|
||||
TASK_APT_STATES=1
|
||||
;;
|
||||
--no-apt-states)
|
||||
TASK_APT_STATES=0
|
||||
;;
|
||||
|
||||
--apt-config)
|
||||
TASK_APT_CONFIG=1
|
||||
;;
|
||||
--no-apt-config)
|
||||
TASK_APT_CONFIG=0
|
||||
;;
|
||||
|
||||
--packages)
|
||||
TASK_PACKAGES=1
|
||||
;;
|
||||
|
@ -988,20 +627,6 @@ while :; do
|
|||
TASK_PACKAGES=0
|
||||
;;
|
||||
|
||||
--processes)
|
||||
TASK_PROCESSES=1
|
||||
;;
|
||||
--no-processes)
|
||||
TASK_PROCESSES=0
|
||||
;;
|
||||
|
||||
--uptime)
|
||||
TASK_UPTIME=1
|
||||
;;
|
||||
--no-uptime)
|
||||
TASK_UPTIME=0
|
||||
;;
|
||||
|
||||
--uname)
|
||||
TASK_UNAME=1
|
||||
;;
|
||||
|
@ -1009,11 +634,25 @@ while :; do
|
|||
TASK_UNAME=0
|
||||
;;
|
||||
|
||||
--netstat)
|
||||
TASK_NETSTAT=1
|
||||
--uptime)
|
||||
TASK_UPTIME=1
|
||||
;;
|
||||
--no-netstat)
|
||||
TASK_NETSTAT=0
|
||||
--no-uptime)
|
||||
TASK_UPTIME=0
|
||||
;;
|
||||
|
||||
--processes)
|
||||
TASK_PROCESSES=1
|
||||
;;
|
||||
--no-processes)
|
||||
TASK_PROCESSES=0
|
||||
;;
|
||||
|
||||
--fstat)
|
||||
TASK_FSTAT=1
|
||||
;;
|
||||
--no-fstat)
|
||||
TASK_FSTAT=0
|
||||
;;
|
||||
|
||||
--netcfg)
|
||||
|
@ -1023,11 +662,11 @@ while :; do
|
|||
TASK_NETCFG=0
|
||||
;;
|
||||
|
||||
--iptables)
|
||||
TASK_IPTABLES=1
|
||||
--pfctl)
|
||||
TASK_PFCTL=1
|
||||
;;
|
||||
--no-iptables)
|
||||
TASK_IPTABLES=0
|
||||
--no-pfctl)
|
||||
TASK_PFCTL=0
|
||||
;;
|
||||
|
||||
--sysctl)
|
||||
|
@ -1037,20 +676,6 @@ while :; do
|
|||
TASK_SYSCTL=0
|
||||
;;
|
||||
|
||||
--virsh)
|
||||
TASK_VIRSH=1
|
||||
;;
|
||||
--no-virsh)
|
||||
TASK_VIRSH=0
|
||||
;;
|
||||
|
||||
--lxc)
|
||||
TASK_LXC=1
|
||||
;;
|
||||
--no-lxc)
|
||||
TASK_LXC=0
|
||||
;;
|
||||
|
||||
--disks)
|
||||
TASK_DISKS=1
|
||||
;;
|
||||
|
@ -1079,18 +704,11 @@ while :; do
|
|||
TASK_DMESG=0
|
||||
;;
|
||||
|
||||
--mysql-processes)
|
||||
TASK_MYSQL_PROCESSES=1
|
||||
--rcctl)
|
||||
TASK_RCCTL=1
|
||||
;;
|
||||
--no-mysql-processes)
|
||||
TASK_MYSQL_PROCESSES=0
|
||||
;;
|
||||
|
||||
--systemctl)
|
||||
TASK_SYSTEMCTL=1
|
||||
;;
|
||||
--no-systemctl)
|
||||
TASK_SYSTEMCTL=0
|
||||
--no-rcctl)
|
||||
TASK_RCCTL=0
|
||||
;;
|
||||
|
||||
--)
|
||||
|
@ -1116,26 +734,19 @@ done
|
|||
: "${VERBOSE:=0}"
|
||||
: "${FORCE:=0}"
|
||||
: "${TASK_ETC:=0}"
|
||||
: "${TASK_DPKG_FULL:=0}"
|
||||
: "${TASK_DPKG_STATUS:=1}"
|
||||
: "${TASK_APT_STATES:=1}"
|
||||
: "${TASK_APT_CONFIG:=1}"
|
||||
: "${TASK_PACKAGES:=1}"
|
||||
: "${TASK_PROCESSES:=1}"
|
||||
: "${TASK_UNAME:=1}"
|
||||
: "${TASK_UPTIME:=1}"
|
||||
: "${TASK_NETSTAT:=1}"
|
||||
: "${TASK_PROCESSES:=1}"
|
||||
: "${TASK_FSTAT:=1}"
|
||||
: "${TASK_NETCFG:=1}"
|
||||
: "${TASK_IPTABLES:=1}"
|
||||
: "${TASK_PFCTL:=1}"
|
||||
: "${TASK_SYSCTL:=1}"
|
||||
: "${TASK_VIRSH:=1}"
|
||||
: "${TASK_LXC:=1}"
|
||||
: "${TASK_DISKS:=1}"
|
||||
: "${TASK_MOUNT:=1}"
|
||||
: "${TASK_DF:=1}"
|
||||
: "${TASK_DMESG:=1}"
|
||||
: "${TASK_MYSQL_PROCESSES:=1}"
|
||||
: "${TASK_SYSTEMCTL:=1}"
|
||||
: "${TASK_RCCTL:=1}"
|
||||
|
||||
export LC_ALL=C
|
||||
|
||||
|
|
Loading…
Reference in New Issue