Initial import
This commit is contained in:
61
application/controllers/tools/Backup.php
Normal file
61
application/controllers/tools/Backup.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
class Backup extends MY_Controller {
|
||||
var $backup_folder;
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
$this->backup_folder = "/data-sda/backup-db/";
|
||||
}
|
||||
public function list_backup() {
|
||||
$cpones = glob($this->backup_folder . 'cpone/*');
|
||||
$cpone_logs = glob($this->backup_folder . 'cpone_log/*');
|
||||
// Recursive function to scan files
|
||||
$files = [];
|
||||
$files["cpone"]= [];
|
||||
foreach ($cpones as $file) {
|
||||
if (is_file($file)) {
|
||||
$files["cpone"][] = [
|
||||
'name' => basename($file),
|
||||
'full_path'=> $file,
|
||||
'last_modified' => date("Y-m-d H:i:s", filemtime($file)),
|
||||
'size' => $this->formatSize(filesize($file))
|
||||
];
|
||||
} else {
|
||||
echo $file . " not file\n";
|
||||
}
|
||||
}
|
||||
|
||||
$files["cpone_log"]= [];
|
||||
foreach ($cpone_logs as $file) {
|
||||
if (is_file($file)) {
|
||||
$files["cpone_log"][] = [
|
||||
'name' => basename($file),
|
||||
'full_path'=> $file,
|
||||
'last_modified' => date("Y-m-d H:i:s", filemtime($file)),
|
||||
'size' => $this->formatSize(filesize($file))
|
||||
];
|
||||
}
|
||||
}
|
||||
// Sort files by last modified date descending
|
||||
usort($files["cpone"], function($a, $b) {
|
||||
return strtotime($b['last_modified']) - strtotime($a['last_modified']);
|
||||
});
|
||||
usort($files["cpone_log"], function($a, $b) {
|
||||
return strtotime($b['last_modified']) - strtotime($a['last_modified']);
|
||||
});
|
||||
|
||||
// Return JSON response
|
||||
echo json_encode(["status"=>"OK","result"=>$files]);
|
||||
}
|
||||
|
||||
private function formatSize($size) {
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
$i = 0;
|
||||
while ($size >= 1024 && $i < count($units) - 1) {
|
||||
$size /= 1024;
|
||||
$i++;
|
||||
}
|
||||
return round($size, 2) . ' ' . $units[$i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user