diff --git a/automation/backup-upload.json.dist b/automation/backup-upload.json.dist index 2d5b6c9..b796b79 100644 --- a/automation/backup-upload.json.dist +++ b/automation/backup-upload.json.dist @@ -1,7 +1,7 @@ { "storageType": "sftp", "ftp": { - "host": "your_sftp_host", + "host": "your_ftp_host", "username": "your_username", "password": "your_password", "port": 21, diff --git a/automation/backup-upload.php b/automation/backup-upload.php index d55dbe6..0323791 100644 --- a/automation/backup-upload.php +++ b/automation/backup-upload.php @@ -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 = $config['directory']; +$directory = "/srv/"; -// Load patterns from config -$patterns = array_map(function ($pattern) use ($currentDateHour) { - return str_replace('{dateHour}', $currentDateHour, $pattern); -}, $config['patterns']); +// Define backup types (prefixes) +$backupTypes = ['database', 'registry', 'panel']; + +// Scan directory and filter matching files +$backupFiles = []; -// Scan directory for matching files $files = scandir($directory); -$filesFound = false; // Flag to track if any files are found - foreach ($files as $file) { - foreach ($patterns as $pattern) { - if (preg_match("/$pattern/", $file)) { - $filesFound = true; - $localPath = $directory . $file; - $remoteFileName = basename($file); - uploadFile($filesystem, $localPath, $remoteFileName, $log, $config['upload']['retries'], $config['upload']['delay']); + foreach ($backupTypes as $type) { + if (preg_match("/^{$type}-\d{8}-\d{4}\.sql\.bz2$/", $file)) { + $backupFiles[$type][$file] = filemtime($directory . $file); } } } +// 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 if (!$filesFound) { $log->info("No matching files found in directory: $directory for patterns: " . implode(', ', $patterns)); diff --git a/automation/backup.json.dist b/automation/backup.json.dist index 52bebcb..6e171a9 100644 --- a/automation/backup.json.dist +++ b/automation/backup.json.dist @@ -36,7 +36,7 @@ } }, { - "name": "Files", + "name": "Registry", "source": { "type": "tar", "options": { @@ -46,7 +46,34 @@ }, "target": { "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" }, "checks": [