improves backup handling of ubl-arch.sh

we now also create daily backups that do not count to the max backup
size and append only a number at the end instead of overwriting the old
(most recent) file
main
Dominic Reich 2 months ago
parent 7293aff6a5
commit d02d09a8ab
Signed by: dominic
GPG Key ID: BC9D6AE1A3BE169A

@ -5,24 +5,31 @@
BFILE=/srv/http/blocked.txt BFILE=/srv/http/blocked.txt
IPFILE=~/ips IPFILE=~/ips
COUNT=$(wc -l ~/ips | cut -d' ' -f1)
if [[ $USER == "root" ]]; then if [[ $USER == "root" ]]; then
echo >&2 "User must not be root! Exiting" echo >&2 "User must not be root! Exiting"
exit 1 exit 1
fi fi
if [[ ! -r $IPFILE ]]; then
echo >&2 "Could not find/open ip file: ${IPFILE}"
exit 1
fi
COUNT=$(wc -l ${IPFILE} | cut -d' ' -f1)
OLDNUM=$(sudo ipset --terse -L | grep "Number of entries:" | cut -d: -f2 | xargs) OLDNUM=$(sudo ipset --terse -L | grep "Number of entries:" | cut -d: -f2 | xargs)
while read ip; do sudo ipset -exist -A badips "$ip"; done < $IPFILE while read ip; do sudo ipset -exist -A badips "$ip"; done < $IPFILE
FILEBACKUP=3 FILEBACKUP=3
TODAY=$(ls ${BFILE}.$(date +%Y%m%d)-* 2>/dev/null| wc -l)
if [ ${FILEBACKUP} -ne 0 ]; then if [ ${FILEBACKUP} -ne 0 ]; then
sudo cp ${BFILE} ${BFILE}.$(date +%Y%m%d) # sudo cp ${BFILE} ${BFILE}.$(date +%Y%m%d)
sudo cp ${BFILE} ${BFILE}.$(date +%Y%m%d)-$(expr ${TODAY} + 1)
fi fi
BACKUPCOUNT=$(ls ${BFILE}.* | wc -l) BACKUPCOUNT=$(expr $(ls ${BFILE}.* | wc -l) - $TODAY - 1)
BACKUPSTODELETE=$(expr ${BACKUPCOUNT} - ${FILEBACKUP}) BACKUPSTODELETE=$(expr ${BACKUPCOUNT} - ${FILEBACKUP})
if [ ${BACKUPCOUNT} -gt ${FILEBACKUP} ]; then if [ ${BACKUPCOUNT} -gt ${FILEBACKUP} ]; then
for f in $(ls -tr ${BFILE}.* | head -${BACKUPSTODELETE}) for f in $(ls -tr ${BFILE}.* | head -${BACKUPSTODELETE})

Loading…
Cancel
Save