{"record":{"id":"37be16947e921632","repo":"nopSolutions/nopCommerce","slug":"backup-file-not-found-filename","errorCode":null,"errorMessage":"Backup file not found: {fileName}","messagePattern":"Backup file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Presentation/Nop.Web/Areas/Admin/Controllers/CommonController.cs","lineNumber":347,"sourceCode":"        return View(model);\n    }\n\n    [HttpPost, ActionName(\"Maintenance\")]\n    [FormValueRequired(\"backupFileName\", \"action\")]\n    [CheckPermission(StandardPermission.System.MANAGE_MAINTENANCE)]\n    public virtual async Task<IActionResult> BackupAction(MaintenanceModel model)\n    {\n        var action = await Request.GetFormValueAsync(\"action\");\n\n        try\n        {\n            var fileName = await Request.GetFormValueAsync(\"backupFileName\");\n            fileName = _fileProvider.GetFileName(_fileProvider.GetAbsolutePath(fileName));\n\n            var backupPath = _maintenanceService.GetBackupPath(fileName);\n\n            if (!_fileProvider.FileExists(backupPath) || _maintenanceService.GetAllBackupFiles().All(f => f != backupPath))\n                throw new FileNotFoundException($\"Backup file not found: {fileName}\");\n\n            switch (action)\n            {\n                case \"delete-backup\":\n                {\n                    _fileProvider.DeleteFile(backupPath);\n                    _notificationService.SuccessNotification(string.Format(await _localizationService.GetResourceAsync(\"Admin.System.Maintenance.BackupDatabase.BackupDeleted\"), fileName));\n                }\n                break;\n\n                case \"restore-backup\":\n                {\n                    await _dataProvider.RestoreDatabaseAsync(backupPath);\n                    _notificationService.SuccessNotification(await _localizationService.GetResourceAsync(\"Admin.System.Maintenance.BackupDatabase.DatabaseRestored\"));\n                }\n                break;\n            }\n        }","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Controllers/CommonController.cs#L329-L365","documentation":"Thrown by CommonController.BackupAction (system maintenance). After reading the form's backupFileName, it normalizes to a filename, resolves the backup path, and throws FileNotFoundException if the file does not exist OR the path is not in GetAllBackupFiles(). It guards against operating on backup files that are absent or outside the managed backup list (also a path-safety check).","triggerScenarios":"POST BackupAction (delete/restore) with a backupFileName whose file was moved/renamed/deleted, or a filename that doesn't match any entry returned by the maintenance service's backup enumeration.","commonSituations":"Manual deletion of the .bak file from the disk while it still shows in the grid; backups stored on a path no longer in the backup directory; permission issue preventing file enumeration; rename/move of backups out of band.","solutions":["Refresh the maintenance backups list and only act on filenames still present.","Confirm the backup directory is readable and the file physically exists at GetBackupPath(fileName).","Ensure no external process moves or renames .bak files out of the configured backup folder."],"exampleFix":"// before\nif (!_fileProvider.FileExists(backupPath) || _maintenanceService.GetAllBackupFiles().All(f => f != backupPath))\n    throw new FileNotFoundException($\"Backup file not found: {fileName}\");\n\n// after (user-friendly notification instead of a 500)\nif (!_fileProvider.FileExists(backupPath) || _maintenanceService.GetAllBackupFiles().All(f => f != backupPath))\n{\n    _notificationService.ErrorNotification(await _localizationService.GetResourceAsync(\"Admin.System.Maintenance.BackupDatabase.BackupNotFound\"));\n    return RedirectToAction(\"Maintenance\");\n}\n","handlingStrategy":"validation","validationCode":"// Confirm the backup file exists and is managed before acting.\nvar fileName = _fileProvider.GetFileName(_fileProvider.GetAbsolutePath(rawName));\nvar path = _maintenanceService.GetBackupPath(fileName);\nif (!_fileProvider.FileExists(path) || _maintenanceService.GetAllBackupFiles().All(f => f != path))\n{\n    _notificationService.ErrorNotification(\"Backup file no longer exists.\");\n    return RedirectToAction(\"Maintenance\");\n}","typeGuard":"static bool BackupFileIsManaged(string path, INopFileProvider fp, IMaintenanceService ms)\n    => fp.FileExists(path) && ms.GetAllBackupFiles().Contains(path);","tryCatchPattern":"try { /* BackupAction body */ }\ncatch (FileNotFoundException ex) when (ex.Message.StartsWith(\"Backup file not found\"))\n{\n    _notificationService.ErrorNotification($\"{ex.Message}. Refresh the backup list.\");\n    return RedirectToAction(\"Maintenance\");\n}","preventionTips":["Refresh the maintenance backups list before delete/restore.","Ensure the backup directory is readable and not modified by external processes.","Do not move/rename .bak files out of the configured backup folder."],"tags":["nopcommerce","admin","backup","file-not-found","maintenance"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}