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

  1. Create the backup directory before listing: ensure the path returned by GetBackupDirectoryPath() exists (Directory.CreateDirectory(path)).
  2. Run the built-in 'Create backup' admin action once, which writes the first .bak file and implicitly creates the folder.
  3. Check file/folder permissions for the application pool identity on the resolved backup path.
  4. 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

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


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/50d4674f6bfe15b0. Report an issue: GitHub.