且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何随时间获取SqlServer数据库备份和还原

更新时间:2023-02-02 16:14:49

在这里是您的问题,可能是:

Is your problem here, possible:

sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
sqlBackup.BackupSetName = "Archive"



如果执行此操作会发生什么情况:



What happens if you do this:

sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToString();
sqlBackup.BackupSetName = "Archive" + DateTime.Now.ToString()


如果我正确理解了您的问题,那么您正在寻找一种解决方案,以防止新备份覆盖旧备份.我想到了两种可能性:

1)将日期和时间作为备份数据库的文件名的一部分.
例如:
If I understand your question correctly, then you''re looking for a solution that will prevent newer backups from overwriting older backups. Two possibilities occur to me:

1) Make the date and time part of the filename that the database is backed up to.
For example:
string backupFilename = databaseName + " [" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "].bak");
BackupDeviceItem deviceItem = new BackupDeviceItem(backupFilename, DeviceType.File);



2)每次备份后,请将完成的.bak文件移动到其他位置,和/或重命名该文件,以便在创建下一个备份时,原始文件不再包含原始文件名.我还是更喜欢选项1.



2) After each backup, move the finished .bak file to a different location, and/or rename it, so that by the time the next backup is created the original file is no longer present with the original filename. I''d prefer option 1 though.