1

Topic: backup_sogo.sh fails to delete old backups

======== Required information ====
- iRedMail version (check /etc/iredmail-release):  0.9.7
- Linux/BSD distribution name and version: CentOS 7
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? NO
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

Hi,
I found an issue inside backup_sogo.sh:
the script is not removing old backups, there problem is that the backup files are stored as "/var/vmail/backup/sogo/{YEAR}/{MONTH}/{DAY}.tar.bz2

[root@mail1 ~]# ls -alh /var/vmail/backup/sogo/2017/08/
total 136K
drwxr-xr-x 2 root root  312 Aug 31 04:01 .
drwxr-xr-x 4 root root   26 Sep  1 04:01 ..
-rw-r--r-- 1 root root 5.1K Aug 15 03:05 15.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 16 04:01 16.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 17 04:01 17.tar.bz2
-rw-r--r-- 1 root root 5.0K Aug 18 04:01 18.tar.bz2
-rw-r--r-- 1 root root 5.0K Aug 19 04:01 19.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 20 04:01 20.tar.bz2
-rw-r--r-- 1 root root 5.0K Aug 21 04:01 21.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 22 04:01 22.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 23 04:01 23.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 24 04:01 24.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 25 04:01 25.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 26 04:01 26.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 27 04:01 27.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 28 04:01 28.tar.bz2
-rw-r--r-- 1 root root 5.0K Aug 29 04:01 29.tar.bz2
-rw-r--r-- 1 root root 5.0K Aug 30 04:01 30.tar.bz2
-rw-r--r-- 1 root root 5.1K Aug 31 04:01 31.tar.bz2

In the other hand, the script tries to delete a directory named "/var/vmail/backup/sogo/{YEAR}/{MONTH}/{DAY}/" that can never be found since in the directory structure there's not a "day" folder but just a "day" file name.

# Find the old backup which should be removed.
export REMOVE_OLD_BACKUP='NO'
if which python &>/dev/null; then
    export REMOVE_OLD_BACKUP='YES'
    py_cmd="import time; import datetime; t=time.localtime(); print datetime.date(t.tm_year, t.tm_mon, t.tm_mday) - datetime.timedelta(days=${KEEP_DAYS})"
    shift_date=$(python -c "${py_cmd}")
    shift_year="$(echo ${shift_date} | awk -F'-' '{print $1}')"
    shift_month="$(echo ${shift_date} | awk -F'-' '{print $2}')"
    shift_day="$(echo ${shift_date} | awk -F'-' '{print $3}')"
    export REMOVED_BACKUP_DIR="${BACKUP_ROOTDIR}/sogo/${shift_year}/${shift_month}/${shift_day}"
fi
if [ X"${REMOVE_OLD_BACKUP}" == X'YES' -a -d ${REMOVED_BACKUP_DIR} ]; then
    echo -e "* Old backup found. Deleting: ${REMOVED_BACKUP_DIR}."
    rm -rf ${REMOVED_BACKUP_DIR} &>/dev/null
fi

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: backup_sogo.sh fails to delete old backups

Fixed moment ago, thanks very much for the feedback:
https://bitbucket.org/zhb/iredmail/comm … 69fb376364