From 3ed72ff22a8d8fd216947b16bf684e2d7e84ee9a Mon Sep 17 00:00:00 2001 From: proura Date: Mon, 5 Dec 2022 14:41:04 +0100 Subject: [PATCH 1/8] Update backup-functions.sh --- usr/share/drlm/lib/backup-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/share/drlm/lib/backup-functions.sh b/usr/share/drlm/lib/backup-functions.sh index 6c618886..bb784400 100644 --- a/usr/share/drlm/lib/backup-functions.sh +++ b/usr/share/drlm/lib/backup-functions.sh @@ -1287,7 +1287,7 @@ function disable_backup () { # Detach NBD device if [ -n "$NBD_DEVICE" ]; then if disable_nbd $NBD_DEVICE; then - LogPrint "- ached NBD device ($NBD_DEVICE)" + LogPrint "- detached NBD device ($NBD_DEVICE)" else Error "- Problem detaching NBD device ($NBD_DEVICE)" fi From 6db8ce92b8ccf89bdefb64c1e995c00c16671bcb Mon Sep 17 00:00:00 2001 From: proura Date: Mon, 5 Dec 2022 14:51:47 +0100 Subject: [PATCH 2/8] Update backup-functions.sh (#201) From cc7d7b290f97f18e93873da2670801758ccfc313 Mon Sep 17 00:00:00 2001 From: Didac Oliveira Date: Wed, 8 Feb 2023 10:50:44 +0100 Subject: [PATCH 3/8] Double check user deletion to skip error code 12 --- usr/share/drlm/lib/install-functions.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/usr/share/drlm/lib/install-functions.sh b/usr/share/drlm/lib/install-functions.sh index abbe1a92..83315acc 100644 --- a/usr/share/drlm/lib/install-functions.sh +++ b/usr/share/drlm/lib/install-functions.sh @@ -337,8 +337,13 @@ function delete_drlm_user () { local CLI_NAME=$2 local DRLM_USER=$3 local SUDO=$4 - ssh $SSH_OPTS -p $SSH_PORT $USER@$CLI_NAME "$SUDO /usr/sbin/userdel -r $DRLM_USER" &> /dev/null - if [ $? -eq 0 ];then return 0; else return 1; fi + ssh $SSH_OPTS -p $SSH_PORT $USER@$CLI_NAME "$SUDO /usr/sbin/userdel -f -r $DRLM_USER" &> /dev/null + if [ $? -eq 0 ];then return 0; + else + sleep 0.5 + ssh $SSH_OPTS -p $SSH_PORT ${USER}@${CLI_NAME} ${SUDO} id ${DRLM_USER} &> /dev/null + if [ $? -eq 0 ]; then return 1; else return 0; fi + fi } function disable_drlm_user_login () { From 92bb0019fd4b4bb89ac1a488b0fe562275a8bc10 Mon Sep 17 00:00:00 2001 From: Didac Oliveira Date: Fri, 10 Feb 2023 10:31:03 +0100 Subject: [PATCH 4/8] Solved import backup always skipping to import client config (#207) --- .../imp/default/049_get_import_backup_configuration.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/usr/share/drlm/backup/imp/default/049_get_import_backup_configuration.sh b/usr/share/drlm/backup/imp/default/049_get_import_backup_configuration.sh index 2913dbc1..f8d8e37f 100644 --- a/usr/share/drlm/backup/imp/default/049_get_import_backup_configuration.sh +++ b/usr/share/drlm/backup/imp/default/049_get_import_backup_configuration.sh @@ -119,11 +119,11 @@ fi # At this point is available the content of the DR file # If exists *.*.drlm.cfg file in the mountpoint it means that is a backup done with a DRLM 2.4.0 or superior -if [ -f "$TMP_MOUNTPOINT/*.*.drlm.cfg" ]; then +IMP_CFG_FILE="$(ls $TMP_MOUNTPOINT/*.*.drlm.cfg)" +if [ -f "$IMP_CFG_FILE" ]; then - IMP_CFG_FILE="$(ls $TMP_MOUNTPOINT/*.*.drlm.cfg)" - IMP_CLI_NAME="$(basename $(ls $TMP_MOUNTPOINT/*.*.drlm.cfg) | awk -F'.' {'print $1'})" - IMP_CLI_CFG="$(basename $(ls $TMP_MOUNTPOINT/*.*.drlm.cfg) | awk -F'.' {'print $2'})" + IMP_CLI_NAME="$(basename "$IMP_CFG_FILE" | awk -F'.' {'print $1'})" + IMP_CLI_CFG="$(basename "$IMP_CFG_FILE" | awk -F'.' {'print $2'})" IMPORT_CONFIGURATION_CONTENT="$(cat $IMP_CFG_FILE)" From 31750309a84f4baf80dd63cd9ffff169a6a995b2 Mon Sep 17 00:00:00 2001 From: proura Date: Fri, 10 Feb 2023 12:50:41 +0100 Subject: [PATCH 5/8] some bugfix and new XML feature (#206) * some bugfix and new XML feature * add JSON to drlm-error-send * https support in xml/json send error * update realease notes --- Makefile | 16 ++- doc/drlm-release-notes.rst | 13 +++ etc/drlm/rsyncd/rsyncd.motd | 2 +- etc/logrotate.d/drlm | 3 +- packaging/debian/changelog | 11 +- packaging/debian/drlm.dsc | 2 +- packaging/debian/postinst | 9 +- packaging/rpm/drlm.spec | 15 ++- usr/sbin/drlm | 2 +- usr/share/drlm/conf/DHCP/config-DHCP.sh | 12 +- usr/share/drlm/conf/default.conf | 61 +++++++++- usr/share/drlm/conf/samples/client_PXE.cfg | 2 +- .../drlm/conf/samples/client_data_only.cfg | 2 +- .../drlm/conf/samples/client_default.cfg | 2 +- .../drlm/conf/samples/client_default.drlm.cfg | 2 +- .../drlm/conf/samples/client_incremental.cfg | 2 +- .../samples/client_incremental_data_only.cfg | 2 +- usr/share/drlm/lib/install-functions.sh | 12 +- usr/share/drlm/lib/report-functions.sh | 78 +++++++++++-- usr/share/drlm/www/drlm-api/drlm-api.go | 2 +- usr/share/drlm/www/drlm-proxy/drlm-proxy.go | 3 +- .../drlm/www/drlm-send-error/configuration.go | 83 ++++++++++++++ .../www/drlm-send-error/drlm-send-error.go | 107 ++++++++++++++++++ usr/share/drlm/www/drlm-send-error/logger.go | 19 ++++ var/lib/drlm/www/index.html | 2 +- var/lib/drlm/www/signin.html | 2 +- 26 files changed, 422 insertions(+), 44 deletions(-) create mode 100644 usr/share/drlm/www/drlm-send-error/configuration.go create mode 100644 usr/share/drlm/www/drlm-send-error/drlm-send-error.go create mode 100644 usr/share/drlm/www/drlm-send-error/logger.go diff --git a/Makefile b/Makefile index 992f21a0..cbbc4cb3 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ drlmbin = usr/sbin/drlm drlm_store_svc = usr/sbin/drlm-stord drlm_api = usr/sbin/drlm-api drlm_proxy = usr/sbin/drlm-proxy +drlm_send_error = usr/sbin/drlm-send-error name = drlm version := $(shell awk 'BEGIN { FS="=" } /VERSION=/ { print $$2 }' $(drlmbin)) @@ -86,6 +87,7 @@ clean: rm -f packaging/docker/src/drlm*.deb rm -f usr/sbin/drlm-api rm -f usr/sbin/drlm-proxy + rm -f usr/sbin/drlm-send-error validate: @echo -e "\033[1m== Validating scripts and configuration ==\033[0;0m" @@ -162,6 +164,7 @@ install-bin: install -Dp -m0755 $(drlm_store_svc) $(DESTDIR)$(sbindir)/drlm-stord install -Dp -m0755 $(drlm_api) $(DESTDIR)$(sbindir)/drlm-api install -Dp -m0755 $(drlm_proxy) $(DESTDIR)$(sbindir)/drlm-proxy + install -Dp -m0755 $(drlm_send_error) $(DESTDIR)$(sbindir)/drlm-send-error install-data: @echo -e "\033[1m== Installing scripts ==\033[0;0m" @@ -215,14 +218,22 @@ else @echo -e "No Go binaries detected to build DRLM PROXY, will be copied the builded one" endif -dist: clean validate drlmapi drlmproxy man rewrite $(name)-$(distversion).tar.gz restore +drlmsenderror: +ifneq ($(shell which go),) + @echo -e "\033[1m== Building DRLM SEND ERROR ==\033[0;0m" + go build -o ./usr/sbin/drlm-send-error ./usr/share/drlm/www/drlm-send-error/ +else + @echo -e "No Go binaries detected to build DRLM SEND ERROR, will be copied the builded one" +endif + +dist: clean validate drlmapi drlmproxy drlmsenderror man rewrite $(name)-$(distversion).tar.gz restore $(name)-$(distversion).tar.gz: @echo -e "\033[1m== Building archive $(name)-$(distversion) ==\033[0;0m" git checkout $(git_branch) git ls-tree -r --name-only --full-tree $(git_branch) | \ tar -czf $(name)-$(distversion).tar.gz --transform='s,^,$(name)-$(distversion)/,S' \ - --files-from=- ./usr/sbin/drlm-api ./usr/share/drlm/www/drlm-api/drlm-api.go ./usr/sbin/drlm-proxy ./usr/share/drlm/www/drlm-proxy/drlm-proxy.go + --files-from=- ./usr/sbin/drlm-api ./usr/sbin/drlm-proxy ./usr/sbin/drlm-send-error rpm: dist @echo -e "\033[1m== Building RPM package $(name)-$(distversion) ==\033[0;0m" @@ -243,6 +254,7 @@ deb: dist rm build-stamp rm usr/sbin/drlm-api rm usr/sbin/drlm-proxy + rm usr/sbin/drlm-send-error docker: dist @echo -e "\033[1m== Building Docker image $(name)-$(distversion) ==\033[0;0m" diff --git a/doc/drlm-release-notes.rst b/doc/drlm-release-notes.rst index 6882afaf..94b22601 100644 --- a/doc/drlm-release-notes.rst +++ b/doc/drlm-release-notes.rst @@ -64,6 +64,19 @@ DRLM are compatible with previous versions, unless otherwise noted. The references pointing to fix #nr or issue #nr refer to our issues tracker +DRLM Version 2.4.10 (February 2023) - Release Notes +--------------------------------------------------- + * Bugfix in installclient tunnig_rear function + + * Bugfix avoid duplicate settings in /etc/drlm/local.conf during update or install process + + * Bugfix in user deletion to skip error code 12 + + * NEW! XML/JSON error reporting supported + + * Bugfix in impbackup client configuration + + DRLM Version 2.4.9 (December 2022) - Release Notes -------------------------------------------------- * Bugfix in importbackup Debian nbd detach diff --git a/etc/drlm/rsyncd/rsyncd.motd b/etc/drlm/rsyncd/rsyncd.motd index dc6fed05..3f830af5 100644 --- a/etc/drlm/rsyncd/rsyncd.motd +++ b/etc/drlm/rsyncd/rsyncd.motd @@ -1 +1 @@ -DRLM server 2.4.9 \ No newline at end of file +DRLM server 2.4.10 \ No newline at end of file diff --git a/etc/logrotate.d/drlm b/etc/logrotate.d/drlm index 7146a9f1..9ba7f74f 100644 --- a/etc/logrotate.d/drlm +++ b/etc/logrotate.d/drlm @@ -2,7 +2,8 @@ /var/log/drlm/drlm-rsyncd.log /var/log/drlm/drlm-sched.log /var/log/drlm/drlm-api.log -/var/log/drlm/drlm-proxy.log { +/var/log/drlm/drlm-proxy.log +/var/log/drlm/drlm-send-error.log { missingok weekly rotate 3 diff --git a/packaging/debian/changelog b/packaging/debian/changelog index c0578ed1..a8318724 100644 --- a/packaging/debian/changelog +++ b/packaging/debian/changelog @@ -1,3 +1,12 @@ +drlm (2.4.10) stable release; urgency=high + * Bugfix in installclient tunnig_rear function + * Bugfix avoid duplicate settings in /etc/drlm/local.conf during update or install process + * Bugfix in user deletion to skip error code 12 + * NEW! XML/JSON error reporting supported + * Bugfix in impbackup client configuration + + -- Pau Roura Fri, 10 Feb 2023 00:00:00 +0100 + drlm (2.4.9) stable release; urgency=high * Bugfix in importbackup Debian nbd detach * Bugfix getting Client OS version fixed @@ -28,8 +37,6 @@ drlm (2.4.6) stable release; urgency=high -- Pau Roura Wed, 21 Sep 2022 00:00:00 +0100 - -- Pau Roura Wed, 21 Sep 2022 00:00:00 +0100 - drlm (2.4.5) stable release; urgency=high * NEW! Improved jobs list with status feedback * NEW! Now is possible to enable and disable Jobs diff --git a/packaging/debian/drlm.dsc b/packaging/debian/drlm.dsc index 3161ba93..25160f70 100644 --- a/packaging/debian/drlm.dsc +++ b/packaging/debian/drlm.dsc @@ -1,6 +1,6 @@ Format: 1.0 Source: drlm -Version: 2.4.9 +Version: 2.4.10 Binary: drlm Maintainer: Pau Roura (pau@brainupdaters.net) Architecture: all diff --git a/packaging/debian/postinst b/packaging/debian/postinst index 615f592e..3e3e0fe3 100755 --- a/packaging/debian/postinst +++ b/packaging/debian/postinst @@ -91,10 +91,13 @@ case "$1" in # DRLM services # ################# - # Set debian like DHCP an NFS service names + # Set debian like DHCP and NFS service names /usr/share/drlm/conf/DHCP/config-DHCP.sh install - [ -f /etc/drlm/local.conf ] && echo "NFS_SVC_NAME=\"nfs-kernel-server\"" >> /etc/drlm/local.conf - + if [ -f /etc/drlm/local.conf ]; then + if ! grep -v '^\s*$\|^\s*\#' /etc/drlm/local.conf | grep -q 'NFS_SVC_NAME="nfs-kernel-server"' ; then + echo "NFS_SVC_NAME=\"nfs-kernel-server\"" >> /etc/drlm/local.conf + fi + fi ;; *) diff --git a/packaging/rpm/drlm.spec b/packaging/rpm/drlm.spec index 9690e602..14528669 100644 --- a/packaging/rpm/drlm.spec +++ b/packaging/rpm/drlm.spec @@ -187,7 +187,9 @@ fi /usr/share/drlm/conf/DHCP/config-DHCP.sh install ### Enable systemd services -echo "NFS_SVC_NAME=\"nfs-server\"" >> /etc/drlm/local.conf +if ! grep -v '^\s*$\|^\s*\#' /etc/drlm/local.conf | grep -q 'NFS_SVC_NAME="nfs-server"'; then + echo "NFS_SVC_NAME=\"nfs-server\"" >> /etc/drlm/local.conf +fi systemctl enable rpcbind.service systemctl enable nfs-server.service systemctl enable dhcpd.service @@ -199,8 +201,8 @@ systemctl is-active --quiet apache2.service && systemctl stop apache2.service systemctl is-enabled --quiet apache2.service && systemctl disable apache2.service %endif %if (0%{?centos} || 0%{?fedora} || 0%{?rhel} || 0%{?rocky} ) -systemctl is-active --quiet httpd.service && systemctl stop httpd.service -systemctl is-enabled --quiet httpd.service && systemctl disable httpd.service +systemctl list-units --full -all | grep -Fq httpd.service && systemctl is-active --quiet httpd.service && systemctl stop httpd.service +systemctl list-units --full -all | grep -Fq httpd.service && systemctl is-enabled --quiet httpd.service && systemctl disable httpd.service %endif fi @@ -263,6 +265,7 @@ systemctl daemon-reload %{_sbindir}/drlm-stord %{_sbindir}/drlm-api %{_sbindir}/drlm-proxy +%{_sbindir}/drlm-send-error %posttrans ### Rcover certificates post transaction @@ -316,6 +319,12 @@ systemctl start drlm-tftpd.service %changelog +* Fri Feb 10 2023 Pau Roura 2.4.10 +- Bugfix in installclient tunnig_rear function +- Bugfix avoid duplicate settings in /etc/drlm/local.conf during update or install process +- Bugfix in user deletion to skip error code 12 +- Bugfix in impbackup client configuration + * Thu Nov 24 2022 Pau Roura 2.4.9 - Bugfix in importbackup Debian nbd detach - Bugfix getting Client OS version fixed diff --git a/usr/sbin/drlm b/usr/sbin/drlm index 09c25d93..7bfd5ff3 100755 --- a/usr/sbin/drlm +++ b/usr/sbin/drlm @@ -48,7 +48,7 @@ readonly INITIAL_BASH_FLAGS_AND_OPTIONS_COMMANDS="$( get_bash_flags_and_options_ # Versioning readonly PRODUCT="Disaster Recovery Linux Manager" readonly PROGRAM=${0##*/} -readonly VERSION=2.4.9 +readonly VERSION=2.4.10 readonly RELEASE_DATE="Git" readonly STARTTIME=$SECONDS diff --git a/usr/share/drlm/conf/DHCP/config-DHCP.sh b/usr/share/drlm/conf/DHCP/config-DHCP.sh index 14cdc0ea..f6a7c04d 100755 --- a/usr/share/drlm/conf/DHCP/config-DHCP.sh +++ b/usr/share/drlm/conf/DHCP/config-DHCP.sh @@ -7,15 +7,21 @@ case $1 in "install") case "$SRV_DISTRO" in debian|ubuntu) - echo "DHCP_SVC_NAME=\"isc-dhcp-server\"" >> /etc/drlm/local.conf + if ! grep -v '^\s*$\|^\s*\#' /etc/drlm/local.conf | grep -q 'DHCP_SVC_NAME="isc-dhcp-server"'; then + echo "DHCP_SVC_NAME=\"isc-dhcp-server\"" >> /etc/drlm/local.conf + fi ;; centos|rhel|rocky) ;; opensuse*|sles*) - echo "DHCP_DIR=\"/etc\"" >> /etc/drlm/local.conf - echo "DHCP_FILE=\"\$DHCP_DIR/dhcpd.conf\"" >> /etc/drlm/local.conf + if ! grep -v '^\s*$\|^\s*\#' /etc/drlm/local.conf | grep -q 'DHCP_DIR="/etc"'; then + echo "DHCP_DIR=\"/etc\"" >> /etc/drlm/local.conf + fi + if ! grep -v '^\s*$\|^\s*\#' /etc/drlm/local.conf | grep -q 'DHCP_FILE="$DHCP_DIR/dhcpd.conf"'; then + echo "DHCP_FILE=\"\$DHCP_DIR/dhcpd.conf\"" >> /etc/drlm/local.conf + fi ;; esac diff --git a/usr/share/drlm/conf/default.conf b/usr/share/drlm/conf/default.conf index 18a40b16..7cb119b4 100644 --- a/usr/share/drlm/conf/default.conf +++ b/usr/share/drlm/conf/default.conf @@ -252,7 +252,7 @@ BKP_CLI_PER=1 # # ERR_REPORT=[yes|no] # default: no -# REPORT_TYPE=[ovo|nsca-ng|nsca|nrdp|zabbix|mail] +# REPORT_TYPE=[ovo|nsca-ng|nsca|nrdp|zabbix|mail|xml|json] # default: empty # ######## @@ -337,6 +337,65 @@ MAIL_TO="root@localhost" MAIL_CC="" MAIL_BCC="" +# +# REPORT_TYPE=[xml|json] +# +# XML VARIABLES +# ============= +# +# These are default values and can be overwritten in local.conf according to your XML installation and configuration. +# DRLM_SEND_ERROR_BIN="/usr/sbin/drlm-send-error" #Default drlm-send-error command path +# DRLM_SEND_ERROR_URL="http://servertostorexml:9090/" #Desired URL to send the XML to +# DRLM_SEND_ERROR_MSG= +# If DRLM_SEND_ERROR_MSG is set to "" will be send a default error like the next one: +# +# +# 2.4.10-git +# ERROR +# drlmserver +# drlmclient +# default +# Debian 11.6 +# 2.6/2020-06-17 +# runbackup +# 2023-02-09 09:11:21 drlm:runbackup:drlmclient:ERROR: Client drlmclient SSH Server on 22 port is not available +# +# +# But DRLM_SEND_ERROR_MSG can be customized specifying an XML string containing DRLM runtime environment variables. +# For example: DRLM_SEND_ERROR_MSG='$HOSTNAME$CLI_NAME$NBD_DEVICE$ERRMSG' +# In the header of the runbackup scripts (/usr/share/drlm/backup/run/default/*.sh) you can find all the variables available at any time +# +# JSON VARIABLES +# ============== +# +# These are default values and can be overwritten in local.conf according to your JSON installation and configuration. +# DRLM_SEND_ERROR_BIN="/usr/sbin/drlm-send-error" #Default drlm-send-error command path +# DRLM_SEND_ERROR_URL="http://servertostorejson:9090/" #Desired URL to send the JSON to +# DRLM_SEND_ERROR_MSG= +# If DRLM_SEND_ERROR_MSG is set to "" will be send a default error like the next one: +# +# { +# "program":"drlm", +# "version":"2.4.10", +# "type":"ERROR", +# "server":"drlmserver", +# "client":"drlmclient", +# "configuration":"default", +# "os":"Debian 11.6", +# "rear":"2.6/2020-06-17", +# "workflow":"runbackup", +# "message":"2023-02-09 11:40:58 drlm:runbackup:drlmclient:ERROR: Client drlmclient SSH Server on 22 port is not available" +# } +# +# But DRLM_SEND_ERROR_MSG can be customized specifying an JSON string containing DRLM runtime environment variables. +# For example: DRLM_SEND_ERROR_MSG=''{\"name\":\"$HOSTNAME\", \"backup_type\":\"$DRLM_BKP_TYPE\", \"ERROR\":\"$ERRMSG\"}'' +# In the header of the runbackup scripts (/usr/share/drlm/backup/run/default/*.sh) you can find all the variables available at any time +# + +DRLM_SEND_ERROR_BIN="/usr/sbin/drlm-send-error" +DRLM_SEND_ERROR_URL="" +DRLM_SEND_ERROR_MSG="" + ################ ---- DHCP CONFIGURATION # ######## diff --git a/usr/share/drlm/conf/samples/client_PXE.cfg b/usr/share/drlm/conf/samples/client_PXE.cfg index 7c18006a..3d660ac0 100644 --- a/usr/share/drlm/conf/samples/client_PXE.cfg +++ b/usr/share/drlm/conf/samples/client_PXE.cfg @@ -6,7 +6,7 @@ # for more information. # ############################################################################### -# DRLM v2.4.9 +# DRLM v2.4.10 # # This configuration example does a PXE rescue system and a data backup of all diff --git a/usr/share/drlm/conf/samples/client_data_only.cfg b/usr/share/drlm/conf/samples/client_data_only.cfg index 886c651c..911040d1 100644 --- a/usr/share/drlm/conf/samples/client_data_only.cfg +++ b/usr/share/drlm/conf/samples/client_data_only.cfg @@ -6,7 +6,7 @@ # for more information. # ############################################################################### -# DRLM v2.4.9 +# DRLM v2.4.10 # # This configuration example does a data backup of /home directory of the diff --git a/usr/share/drlm/conf/samples/client_default.cfg b/usr/share/drlm/conf/samples/client_default.cfg index c9b741aa..cb7f8c8c 100644 --- a/usr/share/drlm/conf/samples/client_default.cfg +++ b/usr/share/drlm/conf/samples/client_default.cfg @@ -8,7 +8,7 @@ # (Configuration examples in /usr/share/drlm/conf/samples/) # ############################################################################### -# DRLM v2.4.9 +# DRLM v2.4.10 # # DRLM automatically generates a ReaR configuration file in function of three diff --git a/usr/share/drlm/conf/samples/client_default.drlm.cfg b/usr/share/drlm/conf/samples/client_default.drlm.cfg index 7a8030e6..3ca3655a 100644 --- a/usr/share/drlm/conf/samples/client_default.drlm.cfg +++ b/usr/share/drlm/conf/samples/client_default.drlm.cfg @@ -6,7 +6,7 @@ # for more information. # ############################################################################### -# DRLM v2.4.9 +# DRLM v2.4.10 # # In client.drlm.cfg config file can be set DRLM client specific configurations diff --git a/usr/share/drlm/conf/samples/client_incremental.cfg b/usr/share/drlm/conf/samples/client_incremental.cfg index 28fb2f63..fb980f89 100644 --- a/usr/share/drlm/conf/samples/client_incremental.cfg +++ b/usr/share/drlm/conf/samples/client_incremental.cfg @@ -6,7 +6,7 @@ # for more information. # ############################################################################### -# DRLM v2.4.9 +# DRLM v2.4.10 # # This configuration example does ISO rescue file and an incremental data diff --git a/usr/share/drlm/conf/samples/client_incremental_data_only.cfg b/usr/share/drlm/conf/samples/client_incremental_data_only.cfg index 08ddb3ce..f10fa2c6 100644 --- a/usr/share/drlm/conf/samples/client_incremental_data_only.cfg +++ b/usr/share/drlm/conf/samples/client_incremental_data_only.cfg @@ -6,7 +6,7 @@ # for more information. # ############################################################################### -# DRLM v2.4.9 +# DRLM v2.4.10 # # This configuration example does a data backup of /home directory of the diff --git a/usr/share/drlm/lib/install-functions.sh b/usr/share/drlm/lib/install-functions.sh index 83315acc..6a297b96 100644 --- a/usr/share/drlm/lib/install-functions.sh +++ b/usr/share/drlm/lib/install-functions.sh @@ -527,9 +527,11 @@ function remove_client_scripts () { function tunning_rear () { - local REAR_VERSION=$(rear -V | awk '{print $2}') + local REAR_VERSION=$($SUDO rear -V | awk '{print $2}') if [ "$REAR_VERSION" == "2.00" ]; then - $SUDO sed -i 's%https://$DRLM_SERVER/clients/$DRLM_ID%https://$DRLM_SERVER/clients/$DRLM_ID/config/default%g' /usr/share/rear/lib/drlm-functions.sh + if ! grep -q 'https://$DRLM_SERVER/clients/$DRLM_ID/config/default' /usr/share/rear/lib/drlm-functions.sh; then + $SUDO sed -i 's%https://$DRLM_SERVER/clients/$DRLM_ID%https://$DRLM_SERVER/clients/$DRLM_ID/config/default%g' /usr/share/rear/lib/drlm-functions.sh + fi fi # remove cURL verbose to avoid infinite lines of Debug in some cURL versions @@ -539,11 +541,13 @@ function tunning_rear () { # Solve SELinux autorelabel after recover (RSYNC) if [ -f "/usr/share/rear/restore/default/500_selinux_autorelabel.sh" ]; then - $SUDO sed -i '/^touch \$TARGET_FS_ROOT\/\.autorelabel/i rm -rf \$TARGET_FS_ROOT\/\.autorelabel' /usr/share/rear/restore/default/500_selinux_autorelabel.sh + if ! grep -v '^\s*$\|^\s*\#' /usr/share/rear/restore/default/500_selinux_autorelabel.sh | grep -q 'rm -rf $TARGET_FS_ROOT/.autorelabel'; then + $SUDO sed -i '/^touch \$TARGET_FS_ROOT\/\.autorelabel/i rm -rf \$TARGET_FS_ROOT\/\.autorelabel' /usr/share/rear/restore/default/500_selinux_autorelabel.sh + fi fi # remove rear cron file - if [ -f "/etc/cron.d/rear" ]; then + if $SUDO test -f "/etc/cron.d/rear"; then $SUDO rm -rf /etc/cron.d/rear fi } diff --git a/usr/share/drlm/lib/report-functions.sh b/usr/share/drlm/lib/report-functions.sh index 118e61a8..a12a5837 100644 --- a/usr/share/drlm/lib/report-functions.sh +++ b/usr/share/drlm/lib/report-functions.sh @@ -132,20 +132,70 @@ function report_error_zabbix () { function report_error_mail () { # Report $ERR_MSG through mail # Return 0 for ok, return 1 not ok - local ERRMSG="$@" - local CMDOUT + local ERRMSG="$@" + local CMDOUT - if [[ -f "$MAILCONF" && -x "$MAILCMD" ]]; then - CMDOUT=$( echo "$ERRMSG" | env MAILRC="$MAILCONF" "$MAILCMD" -s "$MAILSUBJECT" -c "$MAIL_CC" -b "$MAIL_BCC" "$MAIL_TO" ) - if [ $? -eq 0 ]; then - return 0 - else - echo "$CMDOUT" - return 1 - fi + if [[ -f "$MAILCONF" && -x "$MAILCMD" ]]; then + CMDOUT=$( echo "$ERRMSG" | env MAILRC="$MAILCONF" "$MAILCMD" -s "$MAILSUBJECT" -c "$MAIL_CC" -b "$MAIL_BCC" "$MAIL_TO" ) + if [ $? -eq 0 ]; then + return 0 else - LogPrint "WARNING:$PROGRAM:REPORTING:$REPORT_TYPE: Missing command and/or configuration file! Error cannot be sent!" + echo "$CMDOUT" + return 1 + fi + else + LogPrint "WARNING:$PROGRAM:REPORTING:$REPORT_TYPE: Missing command and/or configuration file! Error cannot be sent!" + fi +} + +function report_error_XML () { +# Report $ERR_MSG through xml +# Return 0 for ok, return 1 not ok + local ERRMSG="$@" + local CMDOUT + + if [[ -n "$DRLM_SEND_ERROR_URL" && -x "$DRLM_SEND_ERROR_BIN" ]]; then + + if [ -n "$DRLM_SEND_ERROR_MSG" ]; then + DRLM_SEND_ERROR_MSG=$(eval echo \"$DRLM_SEND_ERROR_MSG\") + CMDOUT=$("$DRLM_SEND_ERROR_BIN" "xml" "$DRLM_SEND_ERROR_MSG") + else + CMDOUT=$("$DRLM_SEND_ERROR_BIN" "xml" "$VERSION" "ERROR" "$HOSTNAME" "$CLI_NAME" "$CLI_CFG" "$CLI_DISTO $CLI_RELEASE" "$CLI_REAR" "$WORKFLOW" "$ERRMSG") fi + if [ $? -eq 0 ]; then + return 0 + else + echo "$CMDOUT" + return 1 + fi + else + LogPrint "WARNING:$PROGRAM:REPORTING:$REPORT_TYPE:XML: Missing command and/or configuration file! Error cannot be sent!" + fi +} + +function report_error_JSON () { +# Report $ERR_MSG through json +# Return 0 for ok, return 1 not ok + local ERRMSG="$@" + local CMDOUT + + if [[ -n "$DRLM_SEND_ERROR_URL" && -x "$DRLM_SEND_ERROR_BIN" ]]; then + + if [ -n "$DRLM_SEND_ERROR_MSG" ]; then + DRLM_SEND_ERROR_MSG=$(eval echo \"$DRLM_SEND_ERROR_MSG\") + CMDOUT=$("$DRLM_SEND_ERROR_BIN" "json" "$DRLM_SEND_ERROR_MSG") + else + CMDOUT=$("$DRLM_SEND_ERROR_BIN" "json" "$VERSION" "ERROR" "$HOSTNAME" "$CLI_NAME" "$CLI_CFG" "$CLI_DISTO $CLI_RELEASE" "$CLI_REAR" "$WORKFLOW" "$ERRMSG") + fi + if [ $? -eq 0 ]; then + return 0 + else + echo "$CMDOUT" + return 1 + fi + else + LogPrint "WARNING:$PROGRAM:REPORTING:$REPORT_TYPE:JSON: Missing command and/or configuration file! Error cannot be sent!" + fi } function report_error () { @@ -173,6 +223,12 @@ function report_error () { mail) return $(report_error_mail "$ERRMSG") ;; + xml) + return $(report_error_XML "$ERRMSG") + ;; + json) + return $(report_error_JSON "$ERRMSG") + ;; *) return 1 ;; diff --git a/usr/share/drlm/www/drlm-api/drlm-api.go b/usr/share/drlm/www/drlm-api/drlm-api.go index ae83defa..8f74687c 100644 --- a/usr/share/drlm/www/drlm-api/drlm-api.go +++ b/usr/share/drlm/www/drlm-api/drlm-api.go @@ -1,4 +1,4 @@ -//drlm-api.go +// www/drlm-api/drlm-api.go package main import ( diff --git a/usr/share/drlm/www/drlm-proxy/drlm-proxy.go b/usr/share/drlm/www/drlm-proxy/drlm-proxy.go index c14b9bc4..6b552450 100644 --- a/usr/share/drlm/www/drlm-proxy/drlm-proxy.go +++ b/usr/share/drlm/www/drlm-proxy/drlm-proxy.go @@ -1,5 +1,4 @@ -//www/drlm-proxy/drlm-proxy.go - +// www/drlm-proxy/drlm-proxy.go package main import ( diff --git a/usr/share/drlm/www/drlm-send-error/configuration.go b/usr/share/drlm/www/drlm-send-error/configuration.go new file mode 100644 index 00000000..c452d75e --- /dev/null +++ b/usr/share/drlm/www/drlm-send-error/configuration.go @@ -0,0 +1,83 @@ +package main + +import ( + "bufio" + "os" + "strings" +) + +type Configuration struct { + DRLMSendErrorURL string +} + +var configDRLMSendError Configuration + +func loadDRLMSendErrorConfiguration() { + + if found, tmpValue := getConfigFileVar("/usr/share/drlm/conf/default.conf", "DRLM_SEND_ERROR_URL"); found { + configDRLMSendError.DRLMSendErrorURL = tmpValue + } + if found, tmpValue := getConfigFileVar("/etc/drlm/local.conf", "DRLM_SEND_ERROR_URL"); found { + configDRLMSendError.DRLMSendErrorURL = tmpValue + } + if found, tmpValue := getConfigFileVar("/etc/drlm/site.conf", "DRLM_SEND_ERROR_URL"); found { + configDRLMSendError.DRLMSendErrorURL = tmpValue + } + + if configDRLMSendError.DRLMSendErrorURL == "" { + logger.Println("DRLM_SEND_ERROR_URL not found in DRLM config. Can not send XML/JSON error.") + return + } +} + +func getVarValue(configLine, varName string) (bool, string) { + found := false + foundVAR := "" + tempoVAR := "" + + if strings.Contains(configLine, varName) { + // Remove the text behind # + tempoVAR = strings.TrimSpace(strings.Split(configLine, "#")[0]) + if tempoVAR != "" { + // if the name behind the = is equal the varName + if strings.TrimSpace(strings.Split(tempoVAR, "=")[0]) == varName { + // Get the text behind = + tempoVAR = strings.TrimSpace(strings.Split(tempoVAR, "=")[1]) + // remove " + tempoVAR = strings.Replace(tempoVAR, "\"", "", -1) + // if is not empty assignt to return + found = true + foundVAR = tempoVAR + } + } + } + return found, foundVAR +} + +func getConfigFileVar(configFile, varName string) (bool, string) { + + found := false + foundVAR := "" + + f, e := os.Open(configFile) + if e != nil { + return found, foundVAR + } + defer f.Close() + + // Splits on newlines by default. + scanner := bufio.NewScanner(f) + + for scanner.Scan() { + if searchFound, tempoVAR := getVarValue(scanner.Text(), varName); searchFound { + found = true + foundVAR = tempoVAR + } + } + + if err := scanner.Err(); err != nil { + // Handle the error + } + + return found, foundVAR +} diff --git a/usr/share/drlm/www/drlm-send-error/drlm-send-error.go b/usr/share/drlm/www/drlm-send-error/drlm-send-error.go new file mode 100644 index 00000000..25a32565 --- /dev/null +++ b/usr/share/drlm/www/drlm-send-error/drlm-send-error.go @@ -0,0 +1,107 @@ +// www/drlm-send-error/drlm-send-error.go + +package main + +import ( + "crypto/tls" + "encoding/json" + "encoding/xml" + "net/http" + "os" + "strings" +) + +type ErrorXML struct { + XMLName xml.Name `xml:"drlm"` + Version string `xml:"version"` + Type string `xml:"type"` + Server string `xml:"server"` + Client string `xml:"client"` + Configuration string `xml:"configuration"` + OS string `xml:"os"` + Rear string `xml:"rear"` + Workflow string `xml:"workflow"` + Message string `xml:"message"` +} + +type ErrorJSON struct { + Program string `json:"program"` + Version string `json:"version"` + Type string `json:"type"` + Server string `json:"server"` + Client string `json:"client"` + Configuration string `json:"configuration"` + OS string `json:"os"` + Rear string `json:"rear"` + Workflow string `json:"workflow"` + Message string `json:"message"` +} + +func main() { + // Load DRLM SEND ERROR configuration vars + loadDRLMSendErrorConfiguration() + + if configDRLMSendError.DRLMSendErrorURL != "" { + + var body []byte + + //If only one argument is provided means that is an XML/JSON string + //else we recieve 9 parameters and have to be Marshalled + if os.Args[1] == "xml" { + if len(os.Args) == 3 { + body = []byte(os.Args[2]) + } else { + error := &ErrorXML{} + error.Version = os.Args[2] + error.Type = os.Args[3] + error.Server = os.Args[4] + error.Client = os.Args[5] + error.Configuration = os.Args[6] + error.OS = os.Args[7] + error.Rear = os.Args[8] + error.Workflow = os.Args[9] + error.Message = os.Args[10] + body, _ = xml.Marshal(error) + } + } else { + if len(os.Args) == 3 { + body = []byte(os.Args[2]) + } else { + error := &ErrorJSON{} + error.Program = "drlm" + error.Version = os.Args[2] + error.Type = os.Args[3] + error.Server = os.Args[4] + error.Client = os.Args[5] + error.Configuration = os.Args[6] + error.OS = os.Args[7] + error.Rear = os.Args[8] + error.Workflow = os.Args[9] + error.Message = os.Args[10] + body, _ = json.Marshal(error) + } + } + + //Log the sended error in /var/log/drlm/drlm-send-error-log + logger.Println("Sending " + os.Args[1] + " error " + string(body) + " to " + configDRLMSendError.DRLMSendErrorURL) + + var resp *http.Response + var err error + + http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + if os.Args[1] == "xml" { + resp, err = http.Post(configDRLMSendError.DRLMSendErrorURL, "application/xml", strings.NewReader(string(body))) + } else { + resp, err = http.Post(configDRLMSendError.DRLMSendErrorURL, "application/json", strings.NewReader(string(body))) + } + + if err != nil { + logger.Println(err) + } + + //Log the response + logger.Println(resp) + } else { + logger.Println("DRLMSendErrorURL not configured. Can not send error.") + } +} diff --git a/usr/share/drlm/www/drlm-send-error/logger.go b/usr/share/drlm/www/drlm-send-error/logger.go new file mode 100644 index 00000000..fb26c328 --- /dev/null +++ b/usr/share/drlm/www/drlm-send-error/logger.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "log" + "os" +) + +var apilog *os.File +var logger *log.Logger + +func init() { + apilog, err := os.OpenFile("/var/log/drlm/drlm-send-error.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + if err != nil { + fmt.Printf("error opening file: %v", err) + os.Exit(1) + } + logger = log.New(apilog, "", log.Lshortfile|log.LstdFlags) +} diff --git a/var/lib/drlm/www/index.html b/var/lib/drlm/www/index.html index 490184c1..c46d7d1a 100644 --- a/var/lib/drlm/www/index.html +++ b/var/lib/drlm/www/index.html @@ -3,7 +3,7 @@ - DRLM v2.4.9 + DRLM v2.4.10 diff --git a/var/lib/drlm/www/signin.html b/var/lib/drlm/www/signin.html index d5cf6854..1214d01b 100644 --- a/var/lib/drlm/www/signin.html +++ b/var/lib/drlm/www/signin.html @@ -36,7 +36,7 @@
Please sign in
var formData = { 'username' : $('input[id=inputUser]').val(), 'password' : $('input[id=inputPassword]').val(), - 'version' : '2.4.9', + 'version' : '2.4.10', 'platform' : 'web' }; From 8c30ab419f851603af07ae11c8082641f5832abe Mon Sep 17 00:00:00 2001 From: Didac Oliveira Date: Fri, 10 Feb 2023 14:08:03 +0100 Subject: [PATCH 6/8] Solve issue at runbackup umounting previous backups (#208) --- usr/share/drlm/lib/backup-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/share/drlm/lib/backup-functions.sh b/usr/share/drlm/lib/backup-functions.sh index bb784400..6ccc51d8 100644 --- a/usr/share/drlm/lib/backup-functions.sh +++ b/usr/share/drlm/lib/backup-functions.sh @@ -410,7 +410,7 @@ function do_umount () { local DEVICE=$1 - /bin/umount $DEVICE >> /dev/null 2>&1 + /bin/umount -f $DEVICE >> /dev/null 2>&1 if [ $? -eq 0 ]; then sleep 1; return 0; else return 1; fi # Return 0 if OK or 1 if NOK } From e5cb92088c268424eadc3ff493ae3dbac8917aeb Mon Sep 17 00:00:00 2001 From: proura Date: Wed, 15 Feb 2023 11:20:54 +0100 Subject: [PATCH 7/8] avoid hidden rsync errors (#209) --- doc/drlm-release-notes.rst | 4 ++++ packaging/debian/changelog | 2 ++ packaging/rpm/drlm.spec | 3 +++ usr/share/drlm/conf/samples/client_default.cfg | 6 +++--- usr/share/drlm/lib/install-functions.sh | 8 ++++++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/drlm-release-notes.rst b/doc/drlm-release-notes.rst index 94b22601..10752f38 100644 --- a/doc/drlm-release-notes.rst +++ b/doc/drlm-release-notes.rst @@ -76,6 +76,10 @@ DRLM Version 2.4.10 (February 2023) - Release Notes * Bugfix in impbackup client configuration + * Bugfix runbackup umounting previous backups + + * Bugfix runbackup rsync hidden warning errors + DRLM Version 2.4.9 (December 2022) - Release Notes -------------------------------------------------- diff --git a/packaging/debian/changelog b/packaging/debian/changelog index a8318724..f0f35403 100644 --- a/packaging/debian/changelog +++ b/packaging/debian/changelog @@ -4,6 +4,8 @@ drlm (2.4.10) stable release; urgency=high * Bugfix in user deletion to skip error code 12 * NEW! XML/JSON error reporting supported * Bugfix in impbackup client configuration + * Bugfix runbackup umounting previous backups + * Bugfix runbackup rsync hidden warning errors -- Pau Roura Fri, 10 Feb 2023 00:00:00 +0100 diff --git a/packaging/rpm/drlm.spec b/packaging/rpm/drlm.spec index 14528669..2c8724ee 100644 --- a/packaging/rpm/drlm.spec +++ b/packaging/rpm/drlm.spec @@ -323,7 +323,10 @@ systemctl start drlm-tftpd.service - Bugfix in installclient tunnig_rear function - Bugfix avoid duplicate settings in /etc/drlm/local.conf during update or install process - Bugfix in user deletion to skip error code 12 +- NEW! XML/JSON error reporting supported - Bugfix in impbackup client configuration +- Bugfix runbackup umounting previous backups +- Bugfix runbackup rsync hidden warning errors * Thu Nov 24 2022 Pau Roura 2.4.9 - Bugfix in importbackup Debian nbd detach diff --git a/usr/share/drlm/conf/samples/client_default.cfg b/usr/share/drlm/conf/samples/client_default.cfg index cb7f8c8c..9a9e8072 100644 --- a/usr/share/drlm/conf/samples/client_default.cfg +++ b/usr/share/drlm/conf/samples/client_default.cfg @@ -21,8 +21,8 @@ # Backup type ISO generates a rescue image in ISO format and backup data is stored # in a DRLM server directory. # -# DRLM_BKP_TYPE=ISO (Default) -# |-- DRLM_BKP_PROT=RSYNC (Default) +# DRLM_BKP_TYPE=ISO #(Default) +# |-- DRLM_BKP_PROT=RSYNC #(Default) # |-- DRLM_BKP_PROT=NETFS # |-- DRLM_BKP_PROG=TAR # |-- DRLM_BKP_PROG=RSYNC @@ -51,7 +51,7 @@ # may be useful to use it by enabling incremental backups, DRLM_INCREMENTAL, also described below. # # DRLM_BKP_TYPE=DATA -# |-- DRLM_BKP_PROT=RSYNC (Default) +# |-- DRLM_BKP_PROT=RSYNC #(Default) # |-- DRLM_BKP_PROT=NETFS # |-- DRLM_BKP_PROG=TAR # |-- DRLM_BKP_PROG=RSYNC diff --git a/usr/share/drlm/lib/install-functions.sh b/usr/share/drlm/lib/install-functions.sh index 6a297b96..45bfdb9c 100644 --- a/usr/share/drlm/lib/install-functions.sh +++ b/usr/share/drlm/lib/install-functions.sh @@ -546,6 +546,14 @@ function tunning_rear () { fi fi + # If rsync reports an error, abort backup process. Only afects rear < 2.7 + if [ -f "/usr/share/rear/backup/RSYNC/default/50_make_rsync_backup.sh" ]; then + sed -i 's/test \"\$_rc\" -gt 0 \&\& VERBOSE\=1 LogPrint \"WARNING !/test \"\$_rc\" -gt 0 \&\& Error \"/g' /usr/share/rear/backup/RSYNC/default/50_make_rsync_backup.sh + fi + if [ -f "/usr/share/rear/backup/RSYNC/default/500_make_rsync_backup.sh" ]; then + sed -i 's/test \"\$_rc\" -gt 0 \&\& VERBOSE\=1 LogPrint \"WARNING !/test \"\$_rc\" -gt 0 \&\& Error \"/g' /usr/share/rear/backup/RSYNC/default/500_make_rsync_backup.sh + fi + # remove rear cron file if $SUDO test -f "/etc/cron.d/rear"; then $SUDO rm -rf /etc/cron.d/rear From fa18a65f8b878c41f5238524d04d5cc2e30b49a8 Mon Sep 17 00:00:00 2001 From: proura Date: Thu, 23 Mar 2023 08:26:26 +0100 Subject: [PATCH 8/8] Update preinst --- packaging/debian/preinst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/debian/preinst b/packaging/debian/preinst index 49f9d529..b7255e06 100755 --- a/packaging/debian/preinst +++ b/packaging/debian/preinst @@ -4,7 +4,7 @@ set -e case "$1" in install) # check host name is not localhost - currhostname="$(/usr/bin/hostname -s)" + currhostname="$(hostname -s)" if [ "$currhostname" = "localhost" ]; then echo "Its important that DRLM servers have a valid hostname. Please change \"localhost\" host name. " exit 1