Database Backups
Before updating a Business Central instance, a backup of the database is created, which is then restored if the update fails. This allows the system to rollback the instance to the same state as before the upgrade, automatically.
You can select between different backup methods by setting the argument bc-server.DatabaseBackupMethod = '...' on installation. The different methods are described below.
Local Backup
The default backup method is LocalBackup, which creates a backup file on the filesystem. No backup is created if the SQL server is running on a different machine than the installation process.
Manual Recovery
In cases where both the update and rollback fails, you must manually recover the database. Re-running the update without doing so, will result in an error, instructing you to recover the database.
You must manually restore the database backup, which resides in the following location:
PATH-TO-INSTANCE-INSTALL-DIRECTORY\INSTANCE-NAME\Upgrade\Database\database.bak
or by default
C:\Program Files\LS Retail\Update Service\Instances\INSTANCE-NAME\Upgrade\Database\database.bak
where INSTANCE-NAME is the name of the current instance.
Then move the database backup to a new location of your choice or delete it.
Snapshot
Instead of creating backup file, you can create a snapshot of the database as a form of backup.
Set bc-server.DatabaseBackupMethod to Snapshot to select this method:
Import-Module UpdateService
$Arguments = @{
'bc-server' = @{
'DatabaseBackupMethod' = 'Snapshot'
}
}
Install-UscPackage -Id 'bc-server' -InstanceName 'BC' -Arguments $Arguments
See here for prerequisites and limitations of snapshots.
Manual Recovery
In cases where both the update and rollback fails, you must manually recover the database. Re-running the update without doing so, will result in an error, instructing you to recover the database.
You must manually restore the database backup, the snapshot is called {DB-NAME}_BAK_{INSTALLATION-GUID}, where DB-NAME is the original database name and INSTALLATION-GUID is a unique ID for the installation that created the backup.
To restore the database from the snapshot, run the following SQL statement, with the names adjusted:
USE master;
RESTORE DATABASE OrigDbName from
DATABASE_SNAPSHOT = 'OrigDbName_BAK_b61174dc-eab3-4e19-9a47-530a2f773c0f';
GO
You may need to stop any services that are connected to the database.
Then delete the snapshot.
Other Considerations
- A backup is not created if you set bc-server.NoDatabaseUpgrades = 'false'.
- If any other external services modify the database data during the update and it rolls back by restoring the database, the modifications are lost.