From 25767342016486d60316a4072971263cfd7ea3ff Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Mon, 30 Oct 2023 21:49:08 -0500 Subject: [PATCH] Update nodemgmt-scripts.sh --- nodemgmt-scripts.sh | 91 ++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/nodemgmt-scripts.sh b/nodemgmt-scripts.sh index 97568d0a..4e1769f2 100755 --- a/nodemgmt-scripts.sh +++ b/nodemgmt-scripts.sh @@ -578,52 +578,59 @@ UPDATE_DYNDNS(){ } BACKUP_OFFSITEPFSENSE(){ - BAKFOLDER=/opt/Offsite-pfSense_Backups - newBAKFOLDER=${BAKFOLDER}/`date +%Y%m%d-%H%M%S` - mkdir ${newBAKFOLDER} - DOM='01' - DOW='1' - DailyBackupsToKeep=14 - WeeklyBackupsToKeep=12 - MonthlyBackupsToKeep=24 + OFFSITE_PFSENSE_IP='10.2.1.1' + if [ "$(CHECK_HOST ${OFFSITE_PFSENSE_IP})" != "false" ]; then + BAKFOLDER=/mnt/Veeam-pfSense-Backups + newBAKFOLDER=${BAKFOLDER}/`date +%Y%m%d-%H%M%S` + mkdir ${newBAKFOLDER} + DOM='01' + DOW='1' + DailyBackupsToKeep=14 + WeeklyBackupsToKeep=12 + MonthlyBackupsToKeep=24 - ssh root@10.2.1.1 tar -c -f /cf/conf/conf_backup.tar.gz /cf/conf - scp root@10.2.1.1:/cf/conf/conf* ${newBAKFOLDER}/ - ssh root@10.2.1.1 rm -f /cf/conf/conf_backup.tar.gz + ssh root@${OFFSITE_PFSENSE_IP} tar -c -f /cf/conf/conf_backup.tar.gz /cf/conf + scp root@${OFFSITE_PFSENSE_IP}:/cf/conf/conf* ${newBAKFOLDER}/ + ssh root@${OFFSITE_PFSENSE_IP} rm -f /cf/conf/conf_backup.tar.gz - if [ "$(date +%d)" == "${DOM}" ] && [ "$(date +%u)" == "${DOW}" ]; then - mv ${newBAKFOLDER} "${newBAKFOLDER}-M" - ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-W" - ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" - elif [ "$(date +%d)" == "${DOM}" ]; then - mv ${newBAKFOLDER} "${newBAKFOLDER}-M" - ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" - elif [ "$(date +%u)" == "${DOW}" ]; then - mv ${newBAKFOLDER} "${newBAKFOLDER}-W" - ln -s "${newBAKFOLDER}-W" "${newBAKFOLDER}-D" - else - mv ${newBAKFOLDER} "${newBAKFOLDER}-D" - fi - - dailyfilestokeep=(`ls -d ${BAKFOLDER}/*-D 2> /dev/null | tail -${DailyBackupsToKeep}`) - weeklyfilestokeep=(`ls -d ${BAKFOLDER}/*-W 2> /dev/null | tail -${WeeklyBackupsToKeep}`) - monthlyfilestokeep=(`ls -d ${BAKFOLDER}/*-M 2> /dev/null | tail -${MonthlyBackupsToKeep}`) - for i in $(ls -d ${BAKFOLDER}/*); do keep=0 - if [[ "${i}" == *"-D"* ]]; then - filestokeep=${dailyfilestokeep[@]} - elif [[ "${i}" == *"-W"* ]]; then - filestokeep=${weeklyfilestokeep[@]} - elif [[ "${i}" == *"-M"* ]]; then - filestokeep=${monthlyfilestokeep[@]} + if [ "$(date +%d)" == "${DOM}" ] && [ "$(date +%u)" == "${DOW}" ]; then + mv ${newBAKFOLDER} "${newBAKFOLDER}-M" + ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-W" + ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" + elif [ "$(date +%d)" == "${DOM}" ]; then + mv ${newBAKFOLDER} "${newBAKFOLDER}-M" + ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" + elif [ "$(date +%u)" == "${DOW}" ]; then + mv ${newBAKFOLDER} "${newBAKFOLDER}-W" + ln -s "${newBAKFOLDER}-W" "${newBAKFOLDER}-D" + else + mv ${newBAKFOLDER} "${newBAKFOLDER}-D" fi - for a in ${filestokeep}; do - if [ "${i}" == "${a}" ]; then - keep=1; break + + dailyfilestokeep=(`ls -d ${BAKFOLDER}/*-D 2> /dev/null | tail -${DailyBackupsToKeep}`) + weeklyfilestokeep=(`ls -d ${BAKFOLDER}/*-W 2> /dev/null | tail -${WeeklyBackupsToKeep}`) + monthlyfilestokeep=(`ls -d ${BAKFOLDER}/*-M 2> /dev/null | tail -${MonthlyBackupsToKeep}`) + for folder in $(ls -d ${BAKFOLDER}/*); do + if [[ "${folder}" == *"-D"* ]]; then + filestokeep=${dailyfilestokeep[@]} + elif [[ "${folder}" == *"-W"* ]]; then + filestokeep=${weeklyfilestokeep[@]} + elif [[ "${folder}" == *"-M"* ]]; then + filestokeep=${monthlyfilestokeep[@]} fi - done; - [ $keep == 0 ] && rm -rf ${i} - done - + keep=0 + for file in ${filestokeep}; do + if [ "${folder}" == "${file}" ]; then + keep=1; break + fi + done; + # [ $keep == 0 ] && rm -rf ${folder} + # [ $keep == 0 ] && ssh backup@10.10.1.60 rmdir "D:\Offsite-pfSense_Backups\${newBAKFOLDER}" + [ $keep == 0 ] && echo "DELETE FOLDER: ${folder}" + done + else + SENDNOTICE "Offsite pfSense Backup Failed" "Could not contact 'pfSense @ ${OFFSITE_PFSENSE_IP}' for backup" + fi } RUN_COMMAND(){