运维开发网

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

运维开发网 https://www.qedev.com 2020-05-23 15:08 出处:网络 作者:运维开发网整理
所以场景是它似乎在创建它时附加到bak文件,是否可以阻止它执行此操作并仅备份当前版本? 这是我的代码 Server backFromServer = new Server(@"server ip add"); backFromServer.ConnectionContext.LoginSecure = false; backFromServer.ConnectionContext.Login =
所以场景是它似乎在创建它时附加到bak文件,是否可以阻止它执行此操作并仅备份当前版本?

这是我的代码

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);
将 Backup.Initialize设置为true:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消