nopSolutions/nopCommerce · error · FileNotFoundException
Backup file not found: {fileName}
Error message
Backup file not found: {fileName} What it means
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).
Source
Thrown at src/Presentation/Nop.Web/Areas/Admin/Controllers/CommonController.cs:347
return View(model);
}
[HttpPost, ActionName("Maintenance")]
[FormValueRequired("backupFileName", "action")]
[CheckPermission(StandardPermission.System.MANAGE_MAINTENANCE)]
public virtual async Task<IActionResult> BackupAction(MaintenanceModel model)
{
var action = await Request.GetFormValueAsync("action");
try
{
var fileName = await Request.GetFormValueAsync("backupFileName");
fileName = _fileProvider.GetFileName(_fileProvider.GetAbsolutePath(fileName));
var backupPath = _maintenanceService.GetBackupPath(fileName);
if (!_fileProvider.FileExists(backupPath) || _maintenanceService.GetAllBackupFiles().All(f => f != backupPath))
throw new FileNotFoundException($"Backup file not found: {fileName}");
switch (action)
{
case "delete-backup":
{
_fileProvider.DeleteFile(backupPath);
_notificationService.SuccessNotification(string.Format(await _localizationService.GetResourceAsync("Admin.System.Maintenance.BackupDatabase.BackupDeleted"), fileName));
}
break;
case "restore-backup":
{
await _dataProvider.RestoreDatabaseAsync(backupPath);
_notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.System.Maintenance.BackupDatabase.DatabaseRestored"));
}
break;
}
}View on GitHub (pinned to 64bdf2ff08)
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.
Example fix
// before
if (!_fileProvider.FileExists(backupPath) || _maintenanceService.GetAllBackupFiles().All(f => f != backupPath))
throw new FileNotFoundException($"Backup file not found: {fileName}");
// after (user-friendly notification instead of a 500)
if (!_fileProvider.FileExists(backupPath) || _maintenanceService.GetAllBackupFiles().All(f => f != backupPath))
{
_notificationService.ErrorNotification(await _localizationService.GetResourceAsync("Admin.System.Maintenance.BackupDatabase.BackupNotFound"));
return RedirectToAction("Maintenance");
}
Defensive patterns
Strategy: validation
Validate before calling
// Confirm the backup file exists and is managed before acting.
var fileName = _fileProvider.GetFileName(_fileProvider.GetAbsolutePath(rawName));
var path = _maintenanceService.GetBackupPath(fileName);
if (!_fileProvider.FileExists(path) || _maintenanceService.GetAllBackupFiles().All(f => f != path))
{
_notificationService.ErrorNotification("Backup file no longer exists.");
return RedirectToAction("Maintenance");
} Type guard
static bool BackupFileIsManaged(string path, INopFileProvider fp, IMaintenanceService ms)
=> fp.FileExists(path) && ms.GetAllBackupFiles().Contains(path); Try / catch
try { /* BackupAction body */ }
catch (FileNotFoundException ex) when (ex.Message.StartsWith("Backup file not found"))
{
_notificationService.ErrorNotification($"{ex.Message}. Refresh the backup list.");
return RedirectToAction("Maintenance");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- This database provider does not support backup
- This database provider does not support database shrinking.
- This database provider does not support backup
- Backup directory not exists
- You cannot delete this email account. At least one account i
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/37be16947e921632.
Report an issue: GitHub.