Search Results for

    Show / Hide Table of Contents

    Database Backups

    Before updating a Business Central instance, the system automatically creates a backup of the database. If the update fails, this backup is used to restore the database, allowing the instance to roll back to its previous state without manual intervention.

    You can choose the backup method by specifying the bc-server.DatabaseBackupMethod argument during installation. The available backup methods and their details are described in the sections below.

    Local Backup

    The default backup method is LocalBackup if the SQL server is local. With this method, the system creates a backup file of the database on the local filesystem before starting the update process.

    Warning

    No backup is created if the SQL Server instance is running on a different machine than where the update installation process is executed. In such cases, you must ensure that you have an up-to-date backup before proceeding with the update.

    Manual Recovery

    If both the update and rollback processes fail, you must manually recover the database before attempting to re-run the update. Failing to do so will result in an error message instructing you to restore the database.

    To manually restore the database backup:

    1. Locate the backup file, which is typically found at:

      PATH-TO-INSTANCE-INSTALL-DIRECTORY\INSTANCE-NAME\Upgrade\Database\database.bak
      

      By default, this path is:

      C:\Program Files\LS Retail\Update Service\Instances\INSTANCE-NAME\Upgrade\Database\database.bak
      

      Replace INSTANCE-NAME with the actual name of your instance.

    2. Stop any services, such as the Business Central service, that are connected to the database to prevent conflicts during the restoration process.

    3. Use your preferred SQL Server management tool to restore the database from the .bak file.

    4. After restoring, you may move the backup file to another location for safekeeping or delete it if it is no longer needed.

    5. Start the Business Central service that was stopped in step 2 and possibly other services that connect to the database.

    Note

    Ensure all services connected to the database are stopped before restoring, to prevent conflicts or data corruption.

    Snapshot

    Instead of creating a backup file, you can use a database snapshot as a backup method. A snapshot provides a read-only, point-in-time copy of the database, which can be quickly reverted if needed.

    To use this method, set bc-server.DatabaseBackupMethod to Snapshot during installation:

    Import-Module UpdateService
    
    $Arguments = @{
        'bc-server' = @{
            'DatabaseBackupMethod' = 'Snapshot'
        }
    }
    
    Install-UscPackage -Id 'bc-server' -InstanceName 'BC' -Arguments $Arguments
    
    Note

    Database snapshots are not supported by all SQL Server editions. Review the prerequisites and limitations before using this method.

    Manual Recovery

    If both the update and rollback processes fail, you must manually recover the database using the snapshot. Attempting to re-run the update without restoring the database will result in an error message instructing you to perform the recovery.

    The snapshot is named {DB-NAME}_BAK_{INSTALLATION-GUID}, where DB-NAME is the original database name and INSTALLATION-GUID is a unique identifier for the installation.

    To manually restore the database from the snapshot:

    1. Stop any services (such as Business Central) that are connected to the database to prevent conflicts during restoration.
    2. Open SQL Server Management Studio or your preferred SQL tool.
    3. Execute the following SQL statement, replacing the names as appropriate:

      USE master;
      RESTORE DATABASE [OrigDbName] FROM
      DATABASE_SNAPSHOT = 'OrigDbName_BAK_b61174dc-eab3-4e19-9a47-530a2f773c0f';
      GO
      

      Replace OrigDbName and the GUID with the actual database name and installation GUID.

    4. After restoring, delete the snapshot to free up resources:

      DROP DATABASE [OrigDbName_BAK_b61174dc-eab3-4e19-9a47-530a2f773c0f];
      GO
      
    5. Restart any services that were stopped in step 1.

    Note

    Ensure all services connected to the database are stopped before restoring, to avoid conflicts or data corruption.

    Other Considerations

    • No backup is created if you set bc-server.NoDatabaseUpgrades to 'false'.
    • If any external services or applications modify the database during the update, and a rollback occurs (restoring the backup or snapshot), those changes will be lost. To prevent data loss, ensure no other processes are writing to the database during the update.
    In This Article
    Back to top Generated by DocFX