nopSolutions/nopCommerce · error · NopException
Backup directory not exists
Error message
Backup directory not exists
What it means
Thrown by GetAllBackupFiles() as a NopException when the configured backup directory does not exist on disk. The method first resolves the directory path via GetBackupDirectoryPath() then checks _fileProvider.DirectoryExists(path). If the folder is missing, the database-backup file listing cannot proceed.
Source
Thrown at src/Libraries/Nop.Services/Common/MaintenanceService.cs:54
if (ensureFolderCreated)
_fileProvider.CreateDirectory(path);
return path;
}
#endregion
#region Methods
/// <summary>
/// Gets all backup files
/// </summary>
/// <returns>Backup file collection</returns>
public virtual IList<string> GetAllBackupFiles()
{
var path = GetBackupDirectoryPath();
if (!_fileProvider.DirectoryExists(path))
throw new NopException("Backup directory not exists");
return _fileProvider.GetFiles(path, $"*.{NopCommonDefaults.DbBackupFileExtension}")
.OrderByDescending(p => _fileProvider.GetLastWriteTime(p)).ToList();
}
/// <summary>
/// Returns the path to the backup file
/// </summary>
/// <param name="backupFileName">The name of the backup file</param>
/// <returns>The path to the backup file</returns>
public virtual string GetBackupPath(string backupFileName)
{
return _fileProvider.Combine(GetBackupDirectoryPath(), backupFileName);
}
/// <summary>
/// Creates a path to a new database backup file
/// </summary>
View on GitHub (pinned to 64bdf2ff08)
Solutions
- Create the backup directory before listing: ensure the path returned by GetBackupDirectoryPath() exists (Directory.CreateDirectory(path)).
- Run the built-in 'Create backup' admin action once, which writes the first .bak file and implicitly creates the folder.
- Check file/folder permissions for the application pool identity on the resolved backup path.
- If hosting in a container, mount a persistent volume at the backup directory path.
Example fix
// before var files = _maintenanceService.GetAllBackupFiles(); // after var dir = _maintenanceService.GetBackupDirectoryPath(); Directory.CreateDirectory(dir); var files = _maintenanceService.GetAllBackupFiles();
Defensive patterns
Strategy: fallback
Validate before calling
var dir = _maintenanceService.GetBackupDirectoryPath();
if (!_fileProvider.DirectoryExists(dir))
Directory.CreateDirectory(dir);
var files = _maintenanceService.GetAllBackupFiles(); Try / catch
IList<string> files;
try { files = _maintenanceService.GetAllBackupFiles(); }
catch (NopException ex) when (ex.Message.Contains("Backup directory"))
{
_logger.LogWarning(ex, "Backup directory missing; returning empty list.");
files = Array.Empty<string>();
} Prevention
- Run one backup-creation action during deployment to seed the folder.
- Mount persistent storage at the backup path in containers.
- Verify application-pool write permissions on App_Data.
When it happens
Trigger: Calling GetAllBackupFiles() on an installation where the backup directory (commonly ~/App_Data/ or the admin-configured path) has never been created or was deleted. Common after a fresh deploy, after moving the App_Data folder, or when file permissions prevent the directory from being enumerated.
Common situations: Fresh installation that has never produced a backup; deployment to a new server where the App_Data/Backups folder was excluded from the published artifacts; containerized hosting with ephemeral storage where the folder isn't in the volume mount.
Related errors
- Backup file not found: {fileName}
- This database provider does not support backup
- This database provider does not support database shrinking.
- Data provider supports connection only with login and passwo
- This database provider does not support backup
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/50d4674f6bfe15b0.
Report an issue: GitHub.