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 : 3.135.202.168
Current Path : /var/www/oasis/src/ |
| Current File : /var/www/oasis/src/backup.php |
<?php
function takebakcup($aobj_context)
{
set_time_limit(300);
$sdb = $_POST['sdb'];
$bkname = "aagneya_tejusent";
$final_array = json_decode($final_array);
array_map('unlink', glob($aobj_context->main_src.'/backup/*.sql'));
$dbhost = 'ls-0413e77c507905dcd339a4d54c3b9a9440fa3a79.cr5ikajncdb2.ap-south-1.rds.amazonaws.com';
$dbuser = 'dbmasteruser';
$dbpass = 'AgneyaSol#2293';
$port = "3306";
$db = "aagneya_tejusent";
$backup_file = $aobj_context->main_src.'backup/aagneya_tejusent.sql';
$files = ['control'];
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$database = 'aagneya_tejusent';
$user = $dbuser;
$pass = $dbpass;
$host = $dbhost;
$dir = $backup_file;
exec("mysqldump --opt --user={$user} --password={$pass} --host={$host} {$database} --result-file={$dir} 2>&1", $output);
$zipname = 'backup/'.$bkname."_".date("Y-m-d-h-i-s").'.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach (glob($aobj_context->main_src.'/backup/*.sql') as $file) {
$zip->addFile($file, basename($file));
}
$zip->close();
if($zipname){
$arr['status'] = 'Backup Successfull';
echo json_encode($arr);
return;
}
}
function formatSizeUnits($bytes)
{
if ($bytes >= 1073741824)
{
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
}
elseif ($bytes >= 1048576)
{
$bytes = number_format($bytes / 1048576, 2) . ' MB';
}
elseif ($bytes >= 1024)
{
$bytes = number_format($bytes / 1024, 2) . ' KB';
}
elseif ($bytes > 1)
{
$bytes = $bytes . ' bytes';
}
elseif ($bytes == 1)
{
$bytes = $bytes . ' byte';
}
else
{
$bytes = '0 bytes';
}
return $bytes;
}
function loadBackUp($aobj_context)
{
$table = '<table width=100% border=1 cellspacing=0 cellpadding=3>
<thead>
<tr>
<th>Sl No.</th>
<th>File Name</th>
<th> Size </th>
<th> Last Modified </th>
<th> Action </th>
</tr>
</thead>
<tbody>';
$i = 1;
$db = "aagneya_tejusent";
$files = glob($aobj_context->main_src."backup/*.zip");
// sort files by last modified date
usort($files, function($x, $y) {
return filemtime($x) < filemtime($y);
});
foreach ($files as $filename)
{
// var_dump($filename);
$del = basename($filename);
$table .='<tr>';
$table .='<td align=center>'.$i.'</td>';
$table .='<td>'.basename($filename).'</td>';
$table .='<td align=right>'.formatSizeUnits(filesize($filename)).'</td>';
$table .='<td align=center>'.date_default_timezone_set("Asia/Kolkata").' '.date("d/m/Y h:i A", filemtime($filename)).'</td>';
$table .='<td align=center> <a href="backup/'.basename($filename).'" target="_blank"> Download </a> <a href="#" style=" color: red;" onclick="delete_zip(`'.$del.'`);"> Delete </a></td>';
$table .='</tr>';
$i++;
}
$table .='</tbody>';
$table .='</table>';
// var_dump($table);
$arr['database'] = $Databasename;
$arr['table'] = $table;
// echo json_encode($arr);
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
return;
}
function delete_zip($aobj_context)
{
$del = $_POST["del"];
$delete_path = $aobj_context->main_src.'backup/'."$del";
if(unlink($delete_path))
{
$data = 1;
echo json_encode($data);
}else{
$data = 0;
echo json_encode($data);
}
}
?>
|