SQL Server Backup

SQL Server Backup

Full Backup

1
backup database AdventureWorks2019 to disk = 'C:\Windows\AdventureWorks2019_20220602.bak';

If get an error like this:

image-20220606100125253

It means that the SQL server has no permission to the location. To fix this, in the SQL Server Configuration Manager, we can find that the SQL service is logged on as NT Service\MSSQLSERVER.

image-20220606100346465

Then right-click on the folder you want to access, properties --> security, and add permission to the NT Service\MSSQLSERVER.

image-20220606100858530

Backup with differential

This will back up the changed pages from the previous full backup.

1
2
-- backup changes start from last full backup, save changed page only
backup database AdventureWorks2019 to disk = 'C:\Users\t-jxie\Downloads\AdventureWorks2019_20220602_2.bak' with differential;

Backup with copy_only

This will leave the DCM (diff change map) unchanged, meaning that if we are back up with differential, it will also backup changes from the last full backup.

1
2
-- backup, leave (DCM) diff change map unchanged, compressed
backup database AdventureWorks2019 to disk = 'C:\Users\t-jxie\Downloads\AdventureWorks2019_20220602_2.bak' with copy_only, compression;

The DCM records the changes made to the page of the database, we can view the DCM of the specific database by

1
dbcc page(5, 1, 6, 2)
image-20220606101710464

Backup log files

1
backup log AdventureWorks2019 to disk = 'C:\Users\t-jxie\Downloads\AdventureWorks2019_20220602.trn';

We can view the information of log files of databases by

1
dbcc sqlperf(logspace)
image-20220606101859208

SQL Server Backup
http://example.com/2022/06/06/SQL Server Backup/
Author
Jiacheng Xie
Posted on
June 6, 2022
Licensed under