<?php
namespace App\System\Task;

class BackupSQLTask {
    public function run_task($task){
        $backupdir = "/var/www/netvay.com/backups";
        $filename = "netvay_itengritr_".date("d_m_Y-H_i")."_backup.sql";
        $database = beGetConfig("database");
        exec("(mysqldump -u{$database["user"]} -p{$database["password"]} {$database["database"]} > {$backupdir}/{$filename}) 2>&1",$a,$b);
        $files = [];
        $filecount = 0;
        foreach(glob($backupdir."/*") as $file){
            $files[] = str_replace($backupdir."/","",$file);
            $filecount += 1;
        }
        if($filecount > 24){
            for($i = 0; $i < $filecount-24; $i++){
                unlink($backupdir."/".$files[$i]);
            }            
        }
    }
}

?>
