mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-14 08:37:00 +02:00
Improvement to backup system
This commit is contained in:
parent
8e72f712b8
commit
ad9b38acf1
3 changed files with 53 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"storageType": "sftp",
|
"storageType": "sftp",
|
||||||
"ftp": {
|
"ftp": {
|
||||||
"host": "your_sftp_host",
|
"host": "your_ftp_host",
|
||||||
"username": "your_username",
|
"username": "your_username",
|
||||||
"password": "your_password",
|
"password": "your_password",
|
||||||
"port": 21,
|
"port": 21,
|
||||||
|
|
|
@ -133,32 +133,38 @@ function uploadFile($filesystem, $localPath, $remotePath, $logger, $retries, $de
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current date and hour in the specified format
|
|
||||||
$currentDateHour = date('Ymd-H'); // Format: YYYYMMDD-HH
|
|
||||||
|
|
||||||
// Directory to check
|
// Directory to check
|
||||||
$directory = $config['directory'];
|
$directory = "/srv/";
|
||||||
|
|
||||||
// Load patterns from config
|
// Define backup types (prefixes)
|
||||||
$patterns = array_map(function ($pattern) use ($currentDateHour) {
|
$backupTypes = ['database', 'registry', 'panel'];
|
||||||
return str_replace('{dateHour}', $currentDateHour, $pattern);
|
|
||||||
}, $config['patterns']);
|
// Scan directory and filter matching files
|
||||||
|
$backupFiles = [];
|
||||||
|
|
||||||
// Scan directory for matching files
|
|
||||||
$files = scandir($directory);
|
$files = scandir($directory);
|
||||||
$filesFound = false; // Flag to track if any files are found
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
foreach ($patterns as $pattern) {
|
foreach ($backupTypes as $type) {
|
||||||
if (preg_match("/$pattern/", $file)) {
|
if (preg_match("/^{$type}-\d{8}-\d{4}\.sql\.bz2$/", $file)) {
|
||||||
$filesFound = true;
|
$backupFiles[$type][$file] = filemtime($directory . $file);
|
||||||
$localPath = $directory . $file;
|
|
||||||
$remoteFileName = basename($file);
|
|
||||||
uploadFile($filesystem, $localPath, $remoteFileName, $log, $config['upload']['retries'], $config['upload']['delay']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Upload the latest file for each type
|
||||||
|
foreach ($backupFiles as $type => $files) {
|
||||||
|
if (!empty($files)) {
|
||||||
|
// Get the latest file by modification time
|
||||||
|
arsort($files);
|
||||||
|
$latestFile = array_key_first($files);
|
||||||
|
|
||||||
|
// Upload file
|
||||||
|
$localPath = $directory . $latestFile;
|
||||||
|
$remoteFileName = basename($latestFile);
|
||||||
|
uploadFile($filesystem, $localPath, $remoteFileName, $log, $config['upload']['retries'], $config['upload']['delay']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Log if no files were found
|
// Log if no files were found
|
||||||
if (!$filesFound) {
|
if (!$filesFound) {
|
||||||
$log->info("No matching files found in directory: $directory for patterns: " . implode(', ', $patterns));
|
$log->info("No matching files found in directory: $directory for patterns: " . implode(', ', $patterns));
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Files",
|
"name": "Registry",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "tar",
|
"type": "tar",
|
||||||
"options": {
|
"options": {
|
||||||
|
@ -46,7 +46,34 @@
|
||||||
},
|
},
|
||||||
"target": {
|
"target": {
|
||||||
"dirname": "/srv",
|
"dirname": "/srv",
|
||||||
"filename": "files-%Y%m%d-%H%i.sql",
|
"filename": "registry-%Y%m%d-%H%i.sql",
|
||||||
|
"compress": "bzip2"
|
||||||
|
},
|
||||||
|
"checks": [
|
||||||
|
{
|
||||||
|
"type": "sizemin",
|
||||||
|
"value": "10M"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cleanup": {
|
||||||
|
"type": "Capacity",
|
||||||
|
"options": {
|
||||||
|
"size": "750M"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Panel",
|
||||||
|
"source": {
|
||||||
|
"type": "tar",
|
||||||
|
"options": {
|
||||||
|
"path": "/var/www/cp",
|
||||||
|
"throttle": "5m"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"target": {
|
||||||
|
"dirname": "/srv",
|
||||||
|
"filename": "panel-%Y%m%d-%H%i.sql",
|
||||||
"compress": "bzip2"
|
"compress": "bzip2"
|
||||||
},
|
},
|
||||||
"checks": [
|
"checks": [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue