HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //bin/clean_backup.sh
#!/bin/bash

today=$( date +%Y%m%d%H%M )
data_atual=$( date +%Y%m%d )

if [ ! -f /etc/locaweb/mybackup/mybackup.conf ] ; then
    /bin/logger "[ERROR] - Problem loading /etc/locaweb/mybackup/mybackup.conf: No such file"
    echo "Problem loading /etc/locaweb/mybackup/mybackup.conf: No such file"
    exit 1
fi

# Cria variaveis para os parametros contidos na conf
# Uso: cfg.parser $conf
#      cfg.section.$section
#      echo $var
cfg.parser(){
    IFS=$'\n' && ini=( $(<$1) )
    ini=( ${ini[*]//;*/} )
    ini=( ${ini[*]/#[/\}$'\n'cfg.section.} )
    ini=( ${ini[*]/%]/ \(} )
    ini=( ${ini[*]/=/=\( } )
    ini=( ${ini[*]/%/ \)} )
    ini=( ${ini[*]/%\( \)/\(\) \{} )
    ini=( ${ini[*]/%\} \)/\}} )
    ini[0]=''
    ini[${#ini[*]} + 1]='}'
    eval "$(echo "${ini[*]}")"
}

clean_backup(){
    retention_days=$1
    backup_path="$2"
    diffig=1

    retention_days=$(($retention_days-$diffig))

    if [[ ! -n "$retention_days" || ! -n "$backup_path" ]] ; then
        /bin/logger "[ERROR] - Wasn't able to get parameters from mybackup.conf"
        return 1
    fi

    days=$(date +%Y%m%d)
    for day in $(seq 0 $retention_days)
    do
        days="$days $( date -d "$day days ago" +%Y%m%d )"
    done

    if [[ $backup_path != "/" ]] ; then
        find $backup_path/ -maxdepth 1 -type d -name "mybackup*[0-9]" | egrep -v "${days// /|}" | xargs -I% rm -rf --preserve-root %
    fi
}

cfg.parser  '/etc/locaweb/mybackup/mybackup.conf'
cfg.section.mybackup

if [ "$1" = "-A" ]; then
    clean_backup $days_to_save $mybackup_path
fi