In case you use Microsoft SQL Server you might heard about the Simple and Full database recovery models. Probably you also know that a Simple recovery model allows you to restore data only at the time of the backup, while Full — at any time (you only need to make regular backups of the transaction log). To restore data with the Full recovery model you will need to apply transaction log backups in a specific sequence. This can be done easily using SQL Server Management Studio (SSMS), but only on the SQL Server where the backups were created.
On a productive SQL server, transaction logs is needed to be backed up regularly to avoid overflowing the transaction log file and automatic growth operations. To get a report about the size of the transaction log (in MB) and in percentage terms with the size of the database itself, execute the T-SQL command:
DBCC SQLPERF(LOGSPACE); GO
The account that is used to start the backup process must have BACKUP DATABASE and BACKUP LOG permissions. To do this, it is enough to add user to the sysadmin role or in one of the predefined database roles — db_owner or db_backupoperator.
There are several ways to create a backup of the transaction log in SQL Server 2016 using SSMS, T-SQL or SQL Server PowerShell.
Tip. You can truncate sql logs and that will free up space in the logical log for reuse of the transaction log.
Backup a Transaction Log Using SQL Server Management Studio
- Run SQL Server Management Studio and connect to the desired SQL Server instance;
- In Object Explorer window select your database, right click on the database name and select Tasks -> Backup;
- Make sure that the database model recovery mode Full or Bulk_Logged is used;
Tip. Simple recovery model does not support transaction log backups
- In the Backup type drop-down list select Transaction Log;
- If necessary, create a new backup destination such as Disk, URL or Tape. In our example, a new file was created on a separate drive E:
- To create a backup, click OK;
- A message should appear “The backup of database DBNAME complete successfully”.
Backup a Transaction Log Using T-SQL
To create a backup of the DB transaction log using T-SQL, create a new Backup Device named DB1device.
To create a backup of the transaction log of the DWConfiguration database on the device DB1device, execute the following command:
BACKUP LOG DWConfiguration TO DB1backup; GO
Or backup transaction log to one disk file:
BACKUP LOG DWConfiguration TO DISK = 'e:\backup\DWConfiguration.TRN'; GO
Backup Transaction Log Using PowerShell
Another way to create a backup of the transaction log is to use the SQL Server PowerShell cmdlet — Backup-SqlDatabase.
Backup-SqlDatabase -ServerInstance SQL2016SP1HOL\MSSQLSERVER -Database DWConfiguration -BackupAction Log
After that, the transaction logs are cleared, and the released space can be overwritten with new transactions.
- Using Process Monitor (ProcMon) to Track File and Registry Changes - October 23, 2020
- Fix: Unable to Find a Default Server with Active Directory Web Services Running - October 23, 2020
- How to Fix Windows 10 Flashing Screen? - October 20, 2020