Milkin Vladimir
Milkin Vladimir

Reputation: 63

Programmatically backup a SQL Server database without it being logged/included in the backup history

I create backups from a MS SQL Server Instance in a C# program I developed.

SqlCommand command = new SqlCommand($"BACKUP DATABASE [{base1C.SqlDbName}] TO 
DISK = N'{tp}' WITH NOFORMAT, INIT, NAME = N'{archiveFileName}', NOSKIP, 
REWIND, NOUNLOAD, STATS = 10, CHECKSUM", connect) {CommandTimeout = 0};

SQL Server remembers backups that are created. How do I create a backup that is not recorded and will not affect other backups or the transaction log?

Upvotes: 2

Views: 226

Answers (1)

marc_s
marc_s

Reputation: 754468

I guess you're looking for a "copy-only backup" - check out the Microsoft Docs on it.

So basically just add a COPY_ONLY option to your backup command (in the WITH section):

SqlCommand command = new SqlCommand($"BACKUP DATABASE [{base1C.SqlDbName}] TO 
DISK = N'{tp}' WITH NOFORMAT, INIT, NAME = N'{archiveFileName}', NOSKIP, 
REWIND, NOUNLOAD, STATS = 10, CHECKSUM, COPY_ONLY", connect) {CommandTimeout = 0};

Upvotes: 1

Related Questions