使用c#备份数据库,bak文件变得越来越大,如何阻止它增长?

时间:2022-06-02 05:58:20

So the scenario is that It seems to append to the bak file when creating it, is it possible to stop it from doing that and just backup the current version?

所以场景是它似乎在创建时附加到bak文件,是否可以阻止它执行此操作并仅备份当前版本?

here is my code

这是我的代码

Server backFromServer = new Server(@"server ip add");
backFromServer.ConnectionContext.LoginSecure = false;
backFromServer.ConnectionContext.Login = "uname";
backFromServer.ConnectionContext.Password = "psd";
Database backFromDb = new Database();
backFromDb = backFromServer.Databases["dbname"];

Backup bkpDatabase = new Backup();
bkpDatabase.Action = BackupActionType.Database;
bkpDatabase.Database = backFromDb.Name;
bkpDatabase.Incremental = false;
bkpDatabase.LogTruncation = BackupTruncateLogType.Truncate;                

BackupDeviceItem bkpDevice = new BackupDeviceItem(@"D:\backupfolder\backup.bak",
                                                  DeviceType.File);

bkpDatabase.Devices.Add(bkpDevice);
bkpDatabase.SqlBackup(backFromServer);

1 个解决方案

#1


7  

Set Backup.Initialize to true:

将Backup.Initialize设置为true:

"If True, the backup specified becomes the first backup set on the media, overwriting any existing backup sets on the media. "

“如果为True,则指定的备份将成为介质上的第一个备份集,将覆盖介质上的所有现有备份集。”

#1


7  

Set Backup.Initialize to true:

将Backup.Initialize设置为true:

"If True, the backup specified becomes the first backup set on the media, overwriting any existing backup sets on the media. "

“如果为True,则指定的备份将成为介质上的第一个备份集,将覆盖介质上的所有现有备份集。”