PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /proc/self/root/opt/sharedrads/guds_modules/deleters/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //proc/self/root/opt/sharedrads/guds_modules/deleters/updraft.py

#!/opt/imh-python/bin/python3
"""Removes Updraft backups older than 7 days"""
from os.path import getctime
from pathlib import Path
from collections import defaultdict
import rads
from guds_modules.base import ModuleBase

REGEX = r".*\/wp-content\/updraft\/backup.+(tar|tmp|gz|zip)$"


class Module(ModuleBase):
    """Removes Updraft backups older than 7 days"""

    def run_module(self, homedir):
        """This function locates updraft backups and handles their deletion"""
        backup_list = self.find(homedir, regex=REGEX, mtime="+7", type='f')
        if not backup_list:
            return {}  # no email
        # if total size is < 10GiB, do nothing
        if sum(map(self.calc_bytes, backup_list)) < 10*2**30:
            self.logger.debug('backups too small, skipping %s', homedir)
            return {}  # no email
        # group by parent directories
        parents: defaultdict[Path, list[Path]] = defaultdict(list)
        for backup in backup_list:
            parents[backup.parent].append(backup)
        for dir_items in parents.values():
            # in each directory, remove all but the latest backup
            if len(dir_items) >= 2:
                dir_items.remove(max(dir_items, key=getctime))
                self.delete_items(dir_items)
        if rads.IMH_CLASS == 'reseller':
            return {}  # no email
        return {
            'template': 379 if rads.IMH_CLASS == 'hub' else 104,
            'variable_1': ', '.join(map(str, parents)),
        }