From 6ac0f0ee9e20b69e94b0809e39da9d77b28b91c9 Mon Sep 17 00:00:00 2001 From: Etienne Allovon Date: Thu, 30 Mar 2023 17:58:03 +0200 Subject: [PATCH 1/7] 6213 - first skeleton for xivo-restore script --- bin/xivo-restore | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 bin/xivo-restore diff --git a/bin/xivo-restore b/bin/xivo-restore new file mode 100644 index 0000000..1a12067 --- /dev/null +++ b/bin/xivo-restore @@ -0,0 +1,74 @@ +#!/bin/bash + +readonly progname="${0##*/}" + +RESTORE_BLINDLY="/etc/asterisk/extensions_extra.d/ + /etc/dahdi/ + /etc/dhcp/ + /etc/network/if-up.d/xivo-routes + /etc/ntp.conf + /etc/resolv.conf + /etc/xivo-xuc.conf + /var/lib/asterisk/agi-bin/ + /var/lib/xivo-provd/ + /var/lib/xivo/" + +PATH_TO_CHECK="/etc/crontab + /etc/ldap/ + /etc/hostname + /etc/hosts + /etc/network/interfaces + /etc/xivo-agentd/ + /etc/xivo-agid/ + /etc/xivo-amid/ + /etc/xivo-auth/ + /etc/xivo-call-logd/ + /etc/xivo-confd/ + /etc/xivo-confgend-client/ + /etc/xivo-ctid/ + /etc/xivo-dird/ + /etc/xivo-dird-phoned/ + /etc/xivo-dxtora/ + /etc/xivo-purge-db/ + /etc/xivo/ + /etc/fail2ban/jail.d/xivo.conf + /etc/fail2ban/filter.d/asterisk-xivo.conf + /etc/fail2ban/filter.d/xivo-provd.conf + /etc/docker/ + /usr/local/bin/ + /usr/local/sbin/ + /var/spool/cron/crontabs/ + /var/lib/postgresql/11/main/*.conf + /var/lib/postgresql/11/main/conf.d/*.conf + /etc/asterisk/" + +usage() { + echo -e "${progname} BACKUP_FILE" + echo -e "This script will restore the backup" + echo "" + echo -e "\t BACKUP_FILE the path to the backup file" +} + +exit_abnormally() { + usage + exit 1 +} + +main() { + local data_backup_file="${1}"; shift + local data_restore_path="/var/tmp/xivo-restore"; shift + + # TODO: Add a filter to the tar command + # to only restore RESTORE_BLINDLY + PATH_TO_CHECK files/paths + tar zxvf "${data_backup_file}" -C "${data_restore_path}" + + # TODO: restore "blindly" the RESTORE_BLINDLY list + #restore_files + + local fingerprint_for_backup=$(mktemp) + find "${data_restore_path}" -type f -print0 | xargs -0 sha1sum > "${fingerprint_for_backup}" + sed -i "s#${data_restore_path}##" "${fingerprint_for_backup}" + sha1sum -c "${fingerprint_for_backup}" +} + +main "${@}" \ No newline at end of file -- GitLab From a5126f8cf7b719cde72897403b39cf8a16de42e7 Mon Sep 17 00:00:00 2001 From: Etienne Allovon Date: Thu, 30 Mar 2023 18:02:40 +0200 Subject: [PATCH 2/7] 6213 - make script executable --- bin/xivo-restore | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 bin/xivo-restore diff --git a/bin/xivo-restore b/bin/xivo-restore old mode 100644 new mode 100755 -- GitLab From 0c325eda63fca2fa8bcf43bcadf6e534d371516a Mon Sep 17 00:00:00 2001 From: Etienne Allovon Date: Thu, 30 Mar 2023 18:05:05 +0200 Subject: [PATCH 3/7] 6213 - check first arg is there --- bin/xivo-restore | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/xivo-restore b/bin/xivo-restore index 1a12067..b621d9e 100755 --- a/bin/xivo-restore +++ b/bin/xivo-restore @@ -43,10 +43,12 @@ PATH_TO_CHECK="/etc/crontab /etc/asterisk/" usage() { - echo -e "${progname} BACKUP_FILE" - echo -e "This script will restore the backup" + echo "Usage:" + echo "${progname} BACKUP_FILE" + echo "This script will restore the backup" echo "" echo -e "\t BACKUP_FILE the path to the backup file" + echo -e "\t e.g. /var/backup/xivo/data.tgz" } exit_abnormally() { @@ -55,6 +57,12 @@ exit_abnormally() { } main() { + if [ -z "${1}" ]; then + echo "Missing parameter: you must give the path to data.tgz file" + echo + exit_abnormally + fi + local data_backup_file="${1}"; shift local data_restore_path="/var/tmp/xivo-restore"; shift -- GitLab From e8d3cf64decb0510dc4bb467f22a2f07ca7d0090 Mon Sep 17 00:00:00 2001 From: PhilemonP Date: Tue, 4 Apr 2023 08:32:11 +0200 Subject: [PATCH 4/7] xivo-restore v0 --- bin/xivo-restore | 117 +++++++++++++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 45 deletions(-) diff --git a/bin/xivo-restore b/bin/xivo-restore index b621d9e..c97f1a6 100755 --- a/bin/xivo-restore +++ b/bin/xivo-restore @@ -2,45 +2,62 @@ readonly progname="${0##*/}" -RESTORE_BLINDLY="/etc/asterisk/extensions_extra.d/ - /etc/dahdi/ - /etc/dhcp/ - /etc/network/if-up.d/xivo-routes - /etc/ntp.conf - /etc/resolv.conf - /etc/xivo-xuc.conf - /var/lib/asterisk/agi-bin/ - /var/lib/xivo-provd/ - /var/lib/xivo/" +## First `/` must be removed from paths to ease the use of tar -PATH_TO_CHECK="/etc/crontab - /etc/ldap/ - /etc/hostname - /etc/hosts - /etc/network/interfaces - /etc/xivo-agentd/ - /etc/xivo-agid/ - /etc/xivo-amid/ - /etc/xivo-auth/ - /etc/xivo-call-logd/ - /etc/xivo-confd/ - /etc/xivo-confgend-client/ - /etc/xivo-ctid/ - /etc/xivo-dird/ - /etc/xivo-dird-phoned/ - /etc/xivo-dxtora/ - /etc/xivo-purge-db/ - /etc/xivo/ - /etc/fail2ban/jail.d/xivo.conf - /etc/fail2ban/filter.d/asterisk-xivo.conf - /etc/fail2ban/filter.d/xivo-provd.conf - /etc/docker/ - /usr/local/bin/ - /usr/local/sbin/ - /var/spool/cron/crontabs/ - /var/lib/postgresql/11/main/*.conf - /var/lib/postgresql/11/main/conf.d/*.conf - /etc/asterisk/" +RESTORE_BLINDLY="etc/asterisk/extensions_extra.d/ + etc/dahdi/ + etc/dhcp/ + etc/network/if-up.d/xivo-routes + etc/ntp.conf + etc/resolv.conf + etc/xivo-xuc.conf + var/lib/asterisk/agi-bin/ + var/lib/xivo-provd/ + var/lib/xivo/" + +PATH_TO_CHECK="etc/crontab + etc/ldap/ + etc/hostname + etc/hosts + etc/network/interfaces + etc/xivo-agentd/ + etc/xivo-agid/ + etc/xivo-amid/ + etc/xivo-auth/ + etc/xivo-call-logd/ + etc/xivo-confd/ + etc/xivo-confgend-client/ + etc/xivo-ctid/ + etc/xivo-dird/ + etc/xivo-dird-phoned/ + etc/xivo-dxtora/ + etc/xivo-purge-db/ + etc/xivo/ + etc/fail2ban/jail.d/xivo.conf + etc/fail2ban/filter.d/asterisk-xivo.conf + etc/fail2ban/filter.d/xivo-provd.conf + etc/docker/ + usr/local/bin/ + usr/local/sbin/ + var/spool/cron/crontabs/ + var/lib/postgresql/11/main/*.conf + var/lib/postgresql/11/main/conf.d/*.conf + etc/asterisk/" + +DO_NOT_RESTORE="etc/asterisk/keys + etc/xivo/default_french_configuration.sql + usr/local/bin/docker-compose + etc/xivo/common.conf + etc/docker/xivo/.env + etc/docker/xivo/factory.env + etc/consul/ + etc/profile.d/xivo_uuid.sh + etc/ssl/ + etc/systemd/ + usr/share/xivo/XIVO-VERSION + var/lib/consul/ + var/log/asterisk/ + var/spool/asterisk/" usage() { echo "Usage:" @@ -66,17 +83,27 @@ main() { local data_backup_file="${1}"; shift local data_restore_path="/var/tmp/xivo-restore"; shift - # TODO: Add a filter to the tar command - # to only restore RESTORE_BLINDLY + PATH_TO_CHECK files/paths - tar zxvf "${data_backup_file}" -C "${data_restore_path}" + ## Only restore RESTORE_BLINDLY + # local restore_blindly_tar=`echo $RESTORE_BLINDLY | awk 'BEGIN{RS = "[ ]"}{sub("/","",$1)}{print $1}'` + echo "Restoring files to be retostred blidnly" + tar -zxf "${data_backup_file}" -C "/" ${RESTORE_BLINDLY} + # Errors(not blocking?) pointing files not found in, archive (e.g. etc/network/if-up.d/xivo-routes) - # TODO: restore "blindly" the RESTORE_BLINDLY list - #restore_files + ## Only restore PATH_TO_CHECK + # local path_to_check_tar=`echo $PATH_TO_CHECK | awk 'BEGIN{RS = "[ ]"}{sub("/","",$1)}{print $1}'` + mkdir "${data_restore_path}" + echo "Restoring files to be checked in ${data_restore_path}" + tar --exclude ${DO_NOT_RESTORE} -zxf "${data_backup_file}" -C "${data_restore_path}" ${PATH_TO_CHECK} --wildcards - local fingerprint_for_backup=$(mktemp) + ## Generate fingerprint for files in $PATH_TO_CHECK + ## Then create a list of changed files + local fingerprint_for_backup="/var/tmp/fingerprint_for_backup.txt" + local files_to_be_checked="/var/tmp/files_to_be_checked.txt" find "${data_restore_path}" -type f -print0 | xargs -0 sha1sum > "${fingerprint_for_backup}" sed -i "s#${data_restore_path}##" "${fingerprint_for_backup}" - sha1sum -c "${fingerprint_for_backup}" + sha1sum -c "${fingerprint_for_backup}" | grep "FAILED" | awk -F ":" '{print $1}' > "${files_to_be_checked}" + gawk -i inplace -v path=${data_restore_path} '{print "vimdiff "$1" "path$1}' ${files_to_be_checked} + echo -e "\e[1;33mYou might want to check differences between old and new files that require attention by reading ${files_to_be_checked}\e[0m" } main "${@}" \ No newline at end of file -- GitLab From 400d322343a989f9c7c5fc8d4e66133eb17a1bed Mon Sep 17 00:00:00 2001 From: PhilemonP Date: Tue, 4 Apr 2023 08:43:12 +0200 Subject: [PATCH 5/7] tipo --- bin/xivo-restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/xivo-restore b/bin/xivo-restore index c97f1a6..e27b57a 100755 --- a/bin/xivo-restore +++ b/bin/xivo-restore @@ -85,7 +85,7 @@ main() { ## Only restore RESTORE_BLINDLY # local restore_blindly_tar=`echo $RESTORE_BLINDLY | awk 'BEGIN{RS = "[ ]"}{sub("/","",$1)}{print $1}'` - echo "Restoring files to be retostred blidnly" + echo "Restoring files to be restored blindly" tar -zxf "${data_backup_file}" -C "/" ${RESTORE_BLINDLY} # Errors(not blocking?) pointing files not found in, archive (e.g. etc/network/if-up.d/xivo-routes) -- GitLab From 8efe775e0240e486664e818797d53ea745a11449 Mon Sep 17 00:00:00 2001 From: Angel KOSTOV Date: Thu, 6 Apr 2023 10:08:53 +0200 Subject: [PATCH 6/7] Bumped version to 2023.04.00 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 56e65d3..4c8f90e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +xivo-utils (2023.04.00) xivo-kuma; urgency=medium + + * Bumped version to 2023.04.00 + + -- Angel KOSTOV Thu, 06 Apr 2023 10:07:24 +0200 + xivo-utils (2022.04.00) xivo-izar; urgency=medium * version bump -- GitLab From cd64b149243ea1b796b68e0f033ec981f0822f15 Mon Sep 17 00:00:00 2001 From: Angel KOSTOV Date: Thu, 6 Apr 2023 10:13:05 +0200 Subject: [PATCH 7/7] Added ticket to changelog --- debian/changelog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 4c8f90e..dee7c83 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ xivo-utils (2023.04.00) xivo-kuma; urgency=medium - * Bumped version to 2023.04.00 + [ Philemon Pommier ] + * 6213 - restore data backup -- Angel KOSTOV Thu, 06 Apr 2023 10:07:24 +0200 -- GitLab