/// <summary> /// 数据库备份逻辑,仅被一键备份调用 /// </summary> private void sqlBackup() { string backupFolderPath = UserInfo.AppPath + "\\SQLBackup"; if (!Directory.Exists(backupFolderPath)) { Directory.CreateDirectory(backupFolderPath); } string backupFullPath = backupFolderPath + "\\backupFull.bak"; string backupDefPath = backupFolderPath + "\\backupDef.bak"; string backupDefLastPath = backupFolderPath + "\\backupDef_last.bak"; ///完整备份可以在两个地方进行,一个时一键智能备份,一个时完整备份按钮,这两个无论怎样, ///都会覆盖完整备份的文件,所以,这里只要检测到完整备份的文件,就只做差异备份 ///没有完整备份的文件,就做完整备份. ///每次完整备份之前,也要做完整备份的备份. ///检查完整备份文件是否存在,若存在,检查上次备份文件是否存在 if (File.Exists(backupFullPath)) { //有完整备份的文件,只做差异备份 //如果有差异备份文件,则改名,再进行差异备份 if (File.Exists(backupDefPath)) { File.Copy(backupDefPath, backupDefLastPath, true); } BackupAndRestored.BackUpDataBase(backupDefPath, UserInfo, listLog2, false); } else { //没有完整备份的文件,做完整备份 BackupAndRestored.BackUpDataBase(backupFullPath, UserInfo, listLog2, true); } }
//数据库单独完整备份 private void skBtnFullSqlBackup_Click(object sender, EventArgs e) { string backupFolderPath = UserInfo.AppPath + "\\SQLBackup"; if (!Directory.Exists(backupFolderPath)) { Directory.CreateDirectory(backupFolderPath); } string backupFullPath = backupFolderPath + "\\backupFull.bak"; string backupFullLastPath = backupFolderPath + "\\backupFull_last.bak"; if (File.Exists(backupFullPath)) { File.Copy(backupFullPath, backupFullLastPath, true); } BackupAndRestored.BackUpDataBase(backupFullPath, UserInfo, listLog2, true); }