public bool DeleteAllDatabases(bool backUpbeforeDelete = true, string destinationDir = null) { if (backUpbeforeDelete) { if (!ExportAllDatabases(destinationDir)) { throw new Exception("Unable to export databases before deleting them"); } } DataBaseParam param = this.InitializeAndGetDataBaseParams(destinationDir); DeleteDirectory(param.DbStorageLocation); return(true); }
public bool ExportAllDatabases(string destinationDir = null) { DataBaseParam param = this.InitializeAndGetDataBaseParams(destinationDir); CleanDirectoryForBackUp(param); CopyDir.Copy(param.DbStorageLocation, param.ExportDir); CopyDir.Copy(param.DestinationFilesStorage, param.ExportDir + "\\" + param.DestinationFilesStorageName); string dest = param.BackUpDir + "\\" + param.ExportDirName + "-" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff") + ".zip"; ZipFile.CreateFromDirectory(param.ExportDir, dest); return(true); }
public void CleanDirectoryForBackUp(DataBaseParam param) { if (!this.databaseService.DataBaseSettings.FileIo.DirectoryExists(param.FinalExportDir)) { this.databaseService.DataBaseSettings.FileIo.CreateDirectory(param.FinalExportDir); } if (!this.databaseService.DataBaseSettings.FileIo.DirectoryExists(param.FinalBackUpDir)) { this.databaseService.DataBaseSettings.FileIo.CreateDirectory(param.FinalBackUpDir); } if (!this.databaseService.DataBaseSettings.FileIo.DirectoryExists(param.FinalExportDir + "\\" + param.DbFileStorageLocationName)) { this.databaseService.DataBaseSettings.FileIo.CreateDirectory(param.FinalExportDir + "\\" + param.DbFileStorageLocationName); } if (this.databaseService.DataBaseSettings.FileIo.DirectoryExists(param.ExportDir)) { DeleteDirectory(param.ExportDir); } if (!this.databaseService.DataBaseSettings.FileIo.DirectoryExists(param.ExportDir)) { this.databaseService.DataBaseSettings.FileIo.CreateDirectory(param.ExportDir); } if (!this.databaseService.DataBaseSettings.FileIo.DirectoryExists(param.BackUpDir)) { this.databaseService.DataBaseSettings.FileIo.CreateDirectory(param.BackUpDir); } if (!this.databaseService.DataBaseSettings.FileIo.DirectoryExists(param.DbStorageLocation)) { this.databaseService.DataBaseSettings.FileIo.CreateDirectory(param.DbStorageLocation); } if (!this.databaseService.DataBaseSettings.FileIo.DirectoryExists(param.DestinationFilesStorage)) { this.databaseService.DataBaseSettings.FileIo.CreateDirectory(param.DestinationFilesStorage); } this.databaseService.DataBaseSettings.FileIo.CreateDirectory(param.ExportDir); }
public DataBaseParam InitializeAndGetDataBaseParams(string destinationDir) { string backUpDir = "PecanDBBackUp"; string exportDir = "PecanDBExport"; if (destinationDir != null) { destinationDir = destinationDir.TrimEnd('/').TrimEnd('\\').TrimEnd('/').TrimEnd('\\'); } var finalBackUpDir = (string.IsNullOrEmpty(destinationDir) ? AppDomain.CurrentDomain.BaseDirectory : destinationDir) + "\\" + backUpDir; var finalExportDir = (string.IsNullOrEmpty(destinationDir) ? AppDomain.CurrentDomain.BaseDirectory : destinationDir) + "\\" + exportDir; var dbStorageLocationName = Path.GetFileName((DataBaseSettings.DbStorageLocation)); var dbFileStorageLocationName = Path.GetFileName((Session.DestinationFilesStorage)); var param = new DataBaseParam { BackUpDir = finalBackUpDir, ExportDir = finalExportDir + "\\" + dbStorageLocationName, BackUpDirName = backUpDir, ExportDirName = exportDir, DbStorageLocation = DataBaseSettings.DbStorageLocation, DestinationFilesStorage = Session.DestinationFilesStorage, DestinationFilesStorageName = dbFileStorageLocationName, UseInMemoryStorage = this.UseInMemoryStorage, DataBaseName = this.DataBaseName, DataBaseStartedAt = this.DataBaseStartedAt, FinalBackUpDir = finalBackUpDir, FinalExportDir = finalExportDir, DbFileStorageLocationName = dbFileStorageLocationName }; CleanDirectoryForBackUp(param); return(param); }