Skip to content

Commit 96c8592

Browse files
authored
Merge pull request #2143 from jaredb7/FPP-Backup-Fix-#2118
Individually read contents of each JSON backup file to avoid memory exhaustion
2 parents e750b18 + 64004c1 commit 96c8592

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

www/api/controllers/backups.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ function GetAvailableJSONBackups(){
308308
$dir_jsonbackups = GetDirSetting('JsonBackups');
309309

310310
//Grabs only the array keys which contain the JSON filenames
311-
$json_config_backup_filenames = (read_directory_files($dir_jsonbackups, true, true, 'asc'));
311+
$json_config_backup_filenames = (read_directory_files($dir_jsonbackups, false, true, 'asc'));
312312
//Process the backup files to extra some info about them
313313
$json_config_backup_filenames = process_jsonbackup_file_data_helper($json_config_backup_filenames, $dir_jsonbackups);
314314

@@ -317,11 +317,11 @@ function GetAvailableJSONBackups(){
317317
$dir_jsonbackupsalternate = GetDirSetting('JsonBackupsAlternate');
318318

319319
//$settings['jsonConfigBackupUSBLocation'] is the selected alternative drive to stop backups to
320-
$json_config_backup_filenames_on_alternative = DriveMountHelper($settings['jsonConfigBackupUSBLocation'], 'read_directory_files', array($dir_jsonbackupsalternate, true, true, 'asc'));
320+
$json_config_backup_filenames_on_alternative = DriveMountHelper($settings['jsonConfigBackupUSBLocation'], 'read_directory_files', array($dir_jsonbackupsalternate, false, true, 'asc'));
321321
//Process the backup files to extra some info about them
322322
$json_config_backup_filenames_on_alternative = process_jsonbackup_file_data_helper($json_config_backup_filenames_on_alternative, $dir_jsonbackupsalternate);
323323
}
324-
//Merge the results together, if t he same backup name exists in the alternative backup location it will overwrite the record from the local cnfig directory
324+
//Merge the results together, if the same backup name exists in the alternative backup location it will overwrite the record from the local cnfig directory
325325
$json_config_backup_filenames_clean = array_merge($json_config_backup_filenames, $json_config_backup_filenames_on_alternative);
326326

327327
//Once merged - do another sort on the entries but sort on the backup_time_unix value
@@ -356,7 +356,8 @@ function process_jsonbackup_file_data_helper($json_config_backup_Data, $source_d
356356
//cleanup the filename so it can be used as as a ID
357357
$backup_filename_clean = trim(str_replace('.json', '', $backup_filename));
358358

359-
$decoded_backup_data = json_decode($backup_data[0], true);
359+
//Read the backup file so we can extract some metadata
360+
$decoded_backup_data = json_decode(file_get_contents($backup_filepath . '/' . $backup_filename), true);
360361
if (array_key_exists('backup_comment', $decoded_backup_data)) {
361362
$backup_data_comment = $decoded_backup_data['backup_comment'];
362363
}
@@ -380,6 +381,8 @@ function process_jsonbackup_file_data_helper($json_config_backup_Data, $source_d
380381
'backup_time' => $backup_date_time,
381382
'backup_time_unix' => $backup_date_time_unix
382383
);
384+
385+
unset($decoded_backup_data);
383386
}
384387

385388
return $json_config_backup_filenames_clean;

www/backup.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,6 @@ function pruneOrRemoveAgedBackupFiles()
22332233

22342234
if ((stripos(strtolower($backup_filename), "-backup_") !== false) && (stripos(strtolower($backup_filename), ".json") !== false)) {
22352235
//
2236-
$backup_comment = $backups_by_trigger_source_meta_data['backup_comment'];
22372236
if (array_key_exists('backup_trigger_source', $backups_by_trigger_source_meta_data) && $backups_by_trigger_source_meta_data['backup_trigger_source'] !== null) {
22382237
//Get the trigger source name & add it and the backup meta data to a temp array, this will group like sources together
22392238
//then we'll limit those lists to enforce our backup limit

0 commit comments

Comments
 (0)