evolinux-base: backup-server-state: add disks and uname state
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
Jérémy Lecour 2022-01-27 12:08:59 +01:00 committed by Jérémy Lecour
parent 6dc17658a9
commit 519228ff9f

View file

@ -2,7 +2,7 @@
PROGNAME="backup-server-state" PROGNAME="backup-server-state"
VERSION="22.01" VERSION="22.01.1"
readonly VERSION readonly VERSION
backup_dir= backup_dir=
@ -57,6 +57,8 @@ Options
--no-virsh no backup copy of virsh list --no-virsh no backup copy of virsh list
--lxc backup copy of lxc list (default) --lxc backup copy of lxc list (default)
--no-lxc no backup copy of lxc list --no-lxc no backup copy of lxc list
--disks backup copy of MBR and partitions (default)
--no-disks no backup copy of MBR and partitions
--mount backup copy of mount points (default) --mount backup copy of mount points (default)
--no-mount no backup copy of mount points --no-mount no backup copy of mount points
--df backup copy of disk usage (default) --df backup copy of disk usage (default)
@ -272,6 +274,21 @@ backup_packages() {
fi fi
} }
backup_uname() {
debug "Backup uname"
last_result=$(uname -a > "${backup_dir}/uname.txt")
last_rc=$?
if [ ${last_rc} -eq 0 ]; then
debug "* uname OK"
else
debug "* uname ERROR"
debug "${last_result}"
rc=10
fi
}
backup_uptime() { backup_uptime() {
debug "Backup uptime" debug "Backup uptime"
@ -505,6 +522,57 @@ backup_lxc() {
fi fi
} }
backup_disks() {
debug "Backup disks"
lsblk_bin=$(command -v lsblk)
awk_bin=$(command -v awk)
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}')
for disk in ${disks}; do
dd_bin=$(command -v dd)
if [ -n "${dd_bin}" ]; then
last_result=$(${dd_bin} if="/dev/${disk}" of="${backup_dir}/MBR-${disk}" bs=512 count=1 2>&1)
last_rc=$?
if [ ${last_rc} -eq 0 ]; then
debug "* dd ${disk} OK"
else
debug "* dd ${disk} ERROR"
debug "${last_result}"
rc=10
fi
else
debug "* dd not found"
fi
fdisk_bin=$(command -v fdisk)
if [ -n "${fdisk_bin}" ]; then
last_result=$(${fdisk_bin} -l "/dev/${disk}" > "${backup_dir}/partitions-${disk}" 2>&1)
last_rc=$?
if [ ${last_rc} -eq 0 ]; then
debug "* fdisk ${disk} OK"
else
debug "* fdisk ${disk} ERROR"
debug "${last_result}"
rc=10
fi
else
debug "* fdisk not found"
fi
done
cat "${backup_dir}"/partitions-* > "${backup_dir}/partitions"
else
if [ -n "${lsblk_bin}" ]; then
debug "* lsblk not found"
fi
if [ -n "${awk_bin}" ]; then
debug "* awk not found"
fi
fi
}
backup_mount() { backup_mount() {
debug "Backup mount points" debug "Backup mount points"
@ -666,6 +734,9 @@ main() {
if [ "${DO_UPTIME}" -eq 1 ]; then if [ "${DO_UPTIME}" -eq 1 ]; then
backup_uptime backup_uptime
fi fi
if [ "${DO_UNAME}" -eq 1 ]; then
backup_uname
fi
if [ "${DO_NETSTAT}" -eq 1 ]; then if [ "${DO_NETSTAT}" -eq 1 ]; then
backup_netstat backup_netstat
fi fi
@ -684,6 +755,9 @@ main() {
if [ "${DO_LXC}" -eq 1 ]; then if [ "${DO_LXC}" -eq 1 ]; then
backup_lxc backup_lxc
fi fi
if [ "${DO_DISKS}" -eq 1 ]; then
backup_disks
fi
if [ "${DO_MOUNT}" -eq 1 ]; then if [ "${DO_MOUNT}" -eq 1 ]; then
backup_mount backup_mount
fi fi
@ -797,6 +871,13 @@ while :; do
DO_UPTIME=0 DO_UPTIME=0
;; ;;
--uname)
DO_UNAME=1
;;
--no-uname)
DO_UNAME=0
;;
--netstat) --netstat)
DO_NETSTAT=1 DO_NETSTAT=1
;; ;;
@ -839,6 +920,13 @@ while :; do
DO_LXC=0 DO_LXC=0
;; ;;
--disks)
DO_DISKS=1
;;
--no-disks)
DO_DISKS=0
;;
--mount) --mount)
DO_MOUNT=1 DO_MOUNT=1
;; ;;
@ -902,6 +990,7 @@ done
: "${DO_APT_CONFIG:=1}" : "${DO_APT_CONFIG:=1}"
: "${DO_PACKAGES:=1}" : "${DO_PACKAGES:=1}"
: "${DO_PROCESSES:=1}" : "${DO_PROCESSES:=1}"
: "${DO_UNAME:=1}"
: "${DO_UPTIME:=1}" : "${DO_UPTIME:=1}"
: "${DO_NETSTAT:=1}" : "${DO_NETSTAT:=1}"
: "${DO_NETCFG:=1}" : "${DO_NETCFG:=1}"
@ -909,6 +998,7 @@ done
: "${DO_SYSCTL:=1}" : "${DO_SYSCTL:=1}"
: "${DO_VIRSH:=1}" : "${DO_VIRSH:=1}"
: "${DO_LXC:=1}" : "${DO_LXC:=1}"
: "${DO_DISKS:=1}"
: "${DO_MOUNT:=1}" : "${DO_MOUNT:=1}"
: "${DO_DF:=1}" : "${DO_DF:=1}"
: "${DO_DMESG:=1}" : "${DO_DMESG:=1}"