Update mm-scripts.sh

This commit is contained in:
2023-07-09 16:15:34 -05:00
parent 3a7bae4611
commit 5a97fdf438

View File

@@ -1071,45 +1071,55 @@ WantedBy=multi-user.target
SERVICEBACKUP(){
type pv >/dev/null 2>&1 || sudo apt -yq install pv >/dev/null 2>&1
usrvc=${1}
msg="Stopping Service and Backing Up"; c=0; spc=''; spc1=$((${cw_spc}-${#msg})); until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
echo -en "${idsCL[White]}${msg}${spc} : ${idsCL[Default]}"
/bin/systemctl stop ${usrvc} >> ${LOGFOLDER}/update.${usrvc}
[ "${usrvc}" == "radarr" ] && /bin/systemctl stop radarr3d >> ${LOGFOLDER}/update.${usrvc}
BACKUPDIR=/opt/Backups/${usrvc}
[ ! -d ${BACKUPDIR} ] && mkdir -p ${BACKUPDIR}
[ "${MM_SERVICE_APP[$usrvc]}" != "" ] && APPBAKFOLDER=${MM_SERVICE_APP[$usrvc]} || APPBAKFOLDER=/opt/${usrvc^}
if [ "${usrvc}" == "all" ]; then
for uasrvc in "${UPDATE_SERVICES[@]}"; do
[ "${MM_UPDATE_REPO[${uasrvc}]}" != "" ] && [[ " ${SERVICES_CHECK[*]} " =~ " ${uasrvc} " ]] && SERVICEBACKUP ${uasrvc} ${2}
done
elif [ "${usrvc}" != "" ]; then
msg="Stopping Service and Backing Up"; c=0; spc=''; spc1=$((${cw_spc}-${#msg})); until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
echo -en "${idsCL[White]}${msg}${spc} : ${idsCL[Default]}"
/bin/systemctl stop ${usrvc} >> ${LOGFOLDER}/update.${usrvc}
[ "${usrvc}" == "radarr" ] && /bin/systemctl stop radarr3d >> ${LOGFOLDER}/update.${usrvc}
if [ "${2}" == "-f" ] ||
([ ! -f ${BACKUPDIR}/cfg-full.tgz ] && [ "${MM_SERVICE_CFG[${usrvc}]}" != "" ] && [ -d ${MM_SERVICE_CFG[${usrvc}]} ]) ||
([ ! -f ${BACKUPDIR}/app-full.tgz ] && [ "${MM_SERVICE_APP[$usrvc]}" != "none" ]) ||
([ $(expr `date +%s` - $(stat -c %Y ${LOGFOLDER}/update.${usrvc})) -gt 604800 ] && [ $(expr `date +%s` - $(stat -c %Y ${BACKUPDIR}/fullbackup)) -gt 7776000 ]); then
if [ "${MM_SERVICE_APP[$usrvc]}" != "none" ]; then
rm -f ${BACKUPDIR}/snapshot-apt.snar
tar -cpPg ${BACKUPDIR}/snapshot-apt.snar -f ${BACKUPDIR}/app-full.tgz ${APPBAKFOLDER}
fi
if [ "${MM_SERVICE_CFG[${usrvc}]}" != "" ] && [ -d ${MM_SERVICE_CFG[${usrvc}]} ]; then
rm -f ${BACKUPDIR}/snapshot-cfg.snar
tar -cpPg ${BACKUPDIR}/snapshot-cfg.snar -f ${BACKUPDIR}/cfg-full.tgz ${MM_SERVICE_CFG[${usrvc}]}
fi
touch ${BACKUPDIR}/fullbackup
else
if [ "${MM_SERVICE_APP[$usrvc]}" != "none" ]; then
tar -cpPg ${BACKUPDIR}/snapshot-apt.snar -f ${BACKUPDIR}/app.$(date +%y-%m-%d-%H-%M-%S).tgz ${APPBAKFOLDER}
fi
if [ "${MM_SERVICE_CFG[${usrvc}]}" != "" ] && [ -d ${MM_SERVICE_CFG[${usrvc}]} ]; then
tar -cpPg ${BACKUPDIR}/snapshot-cfg.snar -f ${BACKUPDIR}/cfg.$(date +%y-%m-%d-%H-%M-%S).tgz ${MM_SERVICE_CFG[${usrvc}]}
fi
fi
BACKUPDIR=/opt/Backups/${usrvc}
[ ! -d ${BACKUPDIR} ] && mkdir -p ${BACKUPDIR}
[ "${MM_SERVICE_APP[$usrvc]}" != "" ] && APPBAKFOLDER=${MM_SERVICE_APP[$usrvc]} || APPBAKFOLDER=/opt/${usrvc^}
for BAKFILE in ${BACKUPDIR}/app.*.tgz; do
[ ${BACKUPDIR}/app-full.tgz -nt ${BAKFILE} ] && rm -f ${BAKFILE}
done
for BAKFILE in ${BACKUPDIR}/cfg.*.tgz; do
[ ${BACKUPDIR}/cfg-full.tgz -nt ${BAKFILE} ] && rm -f ${BAKFILE}
done
if [ "${2}" == "-f" ] ||
([ ! -f ${BACKUPDIR}/cfg-full.tgz ] && [ "${MM_SERVICE_CFG[${usrvc}]}" != "" ] && [ -d ${MM_SERVICE_CFG[${usrvc}]} ]) ||
([ ! -f ${BACKUPDIR}/app-full.tgz ] && [ "${MM_SERVICE_APP[$usrvc]}" != "none" ]) ||
([ $(expr `date +%s` - $(stat -c %Y ${LOGFOLDER}/update.${usrvc})) -gt 604800 ] && [ $(expr `date +%s` - $(stat -c %Y ${BACKUPDIR}/fullbackup)) -gt 7776000 ]); then
if [ "${MM_SERVICE_APP[$usrvc]}" != "none" ]; then
rm -f ${BACKUPDIR}/snapshot-apt.snar
tar -cg ${BACKUPDIR}/snapshot-apt.snar -f ${BACKUPDIR}/app-full.tgz ${APPBAKFOLDER}
fi
if [ "${MM_SERVICE_CFG[${usrvc}]}" != "" ] && [ -d ${MM_SERVICE_CFG[${usrvc}]} ]; then
rm -f ${BACKUPDIR}/snapshot-cfg.snar
rm -f ${BACKUPDIR}/snapshot-cfg-3d.snar
tar -cg ${BACKUPDIR}/snapshot-cfg.snar -f ${BACKUPDIR}/cfg-full.tgz ${MM_SERVICE_CFG[${usrvc}]}
[ "${usrvc}" == "radarr" ] && tar -cg ${BACKUPDIR}/snapshot-cfg-3d.snar -f ${BACKUPDIR}/cfg-3d-full.tgz ${MM_SERVICE_CFG['radarr3d']}
fi
touch ${BACKUPDIR}/fullbackup
else
if [ "${MM_SERVICE_APP[$usrvc]}" != "none" ]; then
tar -cg ${BACKUPDIR}/snapshot-apt.snar -f ${BACKUPDIR}/app.$(date +%y-%m-%d-%H-%M-%S).tgz ${APPBAKFOLDER}
fi
if [ "${MM_SERVICE_CFG[${usrvc}]}" != "" ] && [ -d ${MM_SERVICE_CFG[${usrvc}]} ]; then
tar -cg ${BACKUPDIR}/snapshot-cfg.snar -f ${BACKUPDIR}/cfg.$(date +%y-%m-%d-%H-%M-%S).tgz ${MM_SERVICE_CFG[${usrvc}]}
fi
fi
for BAKFILE in ${BACKUPDIR}/app.*.tgz; do
[ ${BACKUPDIR}/app-full.tgz -nt ${BAKFILE} ] && rm -f ${BAKFILE}
done
for BAKFILE in ${BACKUPDIR}/cfg.*.tgz; do
[ ${BACKUPDIR}/cfg-full.tgz -nt ${BAKFILE} ] && rm -f ${BAKFILE}
done
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
}
}
SERVICEBACKUP.old(){
usrvc=${1}