From a9f0e7588863779c268b8e463a40ca31aa4e1ad5 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sat, 10 May 2025 15:38:31 -0500 Subject: [PATCH] Update nodemgmt-scripts.sh --- nodemgmt-scripts.sh | 54 ++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/nodemgmt-scripts.sh b/nodemgmt-scripts.sh index 61eb1d76..741dd4ba 100755 --- a/nodemgmt-scripts.sh +++ b/nodemgmt-scripts.sh @@ -727,47 +727,51 @@ BACKUP_UNIFINVR(){ if [ $(scp root@${UNIFINVR_IP}:/volume1/*_backup.tar.gz ${BAKFOLDER}/${newBAKFOLDER}/) ]; then ssh -q -o ConnectTimeout=3 -o ConnectionAttempts=1 root@${UNIFINVR_IP} rm -f /volume1/*_backup.tar.gz - + cd ${BAKFOLDER} if [ "$(date +%d)" == "${DOM}" ] && [ "$(date +%u)" == "${DOW}" ]; then + echo "HERE 1"; mv ${newBAKFOLDER} "${newBAKFOLDER}-M" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-W" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" elif [ "$(date +%d)" == "${DOM}" ]; then + echo "HERE 2"; mv ${newBAKFOLDER} "${newBAKFOLDER}-M" ln -s "${newBAKFOLDER}-M" "${newBAKFOLDER}-D" elif [ "$(date +%u)" == "${DOW}" ]; then + echo "HERE 3"; mv ${newBAKFOLDER} "${newBAKFOLDER}-W" ln -s "${newBAKFOLDER}-W" "${newBAKFOLDER}-D" else + echo "HERE 4"; mv ${newBAKFOLDER} "${newBAKFOLDER}-D" fi 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 folder in $(ls -d ${BAKFOLDER}/*); do - # if [ "${folder}" != "${BAKFOLDER}/mounted" ]; then - # if [[ "${folder}" == *"-D"* ]]; then - # filestokeep=${dailyfilestokeep[@]} - # elif [[ "${folder}" == *"-W"* ]]; then - # filestokeep=${weeklyfilestokeep[@]} - # elif [[ "${folder}" == *"-M"* ]]; then - # filestokeep=${monthlyfilestokeep[@]} - # fi - # keep=0 - # for file in ${filestokeep}; do - # if [ "${folder}" == "${file}" ]; then - # keep=1; break - # fi - # done; - # if [ $keep == 0 ]; then - # delFolder="D:\\BackupSync\\UniFi-Backups\\UniFi-NVR_Backups\\${folder##*/}" - # ssh -q -o ConnectTimeout=3 -o ConnectionAttempts=1 backup@10.10.1.60 cmd /C rmdir /S /Q "${delFolder}" - # fi - # fi - # done + 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}" != "${BAKFOLDER}/mounted" ]; then + if [[ "${folder}" == *"-D"* ]]; then + filestokeep=${dailyfilestokeep[@]} + elif [[ "${folder}" == *"-W"* ]]; then + filestokeep=${weeklyfilestokeep[@]} + elif [[ "${folder}" == *"-M"* ]]; then + filestokeep=${monthlyfilestokeep[@]} + fi + keep=0 + for file in ${filestokeep}; do + if [ "${folder}" == "${file}" ]; then + keep=1; break + fi + done; + if [ $keep == 0 ]; then + delFolder="D:\\BackupSync\\UniFi-Backups\\UniFi-NVR_Backups\\${folder##*/}" + ssh -q -o ConnectTimeout=3 -o ConnectionAttempts=1 backup@10.10.1.60 cmd /C rmdir /S /Q "${delFolder}" + fi + fi + done else SENDNOTICE "UniFi-NVR Backup Failed" "Could not contact 'NVR @ ${UNIFINVR_IP}' for backup" 1 fi