private void Restore() { var DB = txtPath.Text; if (DB.EndsWith(".gbk")) { var conexao = new FbConnectionStringBuilder(); conexao.DataSource = "localhost"; conexao.Database = DB; conexao.UserID = "SYSDBA"; conexao.Password = "******"; var restore = new FbRestore(); restore.ConnectionString = conexao.ToString(); var fileInfo = new FileInfo(DB); pathDest = $"{fileInfo.DirectoryName}\\{DB.Substring(0, DB.Length - 3)}eco"; restore.BackupFiles.Add(new FbBackupFile(pathDest)); restore.Verbose = true; restore.ServiceOutput += ServiceOutput; restore.Execute(); } else { Console.WriteLine("ERRO:Arquivo de Backup não encontrado!"); } }
private bool RestauracaoDatabaseFirebird(string arquivoBackup) { try { listBoxInfoRestauracao.Items.Clear(); if (Conexao.OPEN) { Conexao.Close(); } Thread.Sleep(100); string_conexao = @"User="******";Password="******";Database=" + bancoOriginal + ";DataSource=localhost;Port=3050;Dialect=3;"; FbRestore restoreSvc = new FbRestore(); restoreSvc.ServiceOutput += new ServiceOutputEventHandler(restoreSvc_ServiceOutput); restoreSvc.ConnectionString = string_conexao; restoreSvc.BackupFiles.Add(new FbBackupFile(arquivoBackup, 2048)); restoreSvc.Verbose = true; restoreSvc.Options = FbRestoreFlags.Replace; restoreSvc.Execute(); return(true); } catch (Exception ex) { throw new Exception(ex.Message); } }
private static bool RestoreFirebird(string restFileName) { try { if (CONN.State == ConnectionState.Open) { CONN.Close(); } Thread.Sleep(500); String string_conexao = @"User=SYSDBA;Password=jcsoftwares;Database=" + SERVER + BANCO + ";DataSource=localhost;Port=3050;Dialect=3;"; var restoreSvc = new FbRestore { ConnectionString = string_conexao }; restoreSvc.BackupFiles.Add(new FbBackupFile(restFileName, 2048)); restoreSvc.Verbose = true; restoreSvc.Options = FbRestoreFlags.Replace; restoreSvc.Execute(); CONN.Open(); return(true); } catch (Exception ex) { throw new Exception("Erro ao realizar restore do banco.\nDetalhes: " + ex.Message); } }
public void Restore(string source, string dest, TextBox tbLog) { tb = tbLog; if (!File.Exists(source)) { throw new FileNotFoundException("Файл архива базы данных не найден", source); } if (File.Exists(dest)) { throw new IOException("Файл базы данных уже существует"); } tb.Text = String.Format("Начат процесс восстановления базы данных: {0}" + Environment.NewLine, DateTime.Now); //tbLog.AppendText("Source: {0} ({1})", source, GetFileSize(source)); //tbLog.AppendText("Destination: {0}", dest, null); /* * Debug.WriteLine("Restoring database"); * Debug.WriteLine("Source: {0} ({1})", source, GetFileSize(source)); * Debug.WriteLine("Destination: {0}", dest, null); */ string restoreTemp = GetTempName(dest); tb.AppendText(String.Format("Временный файл: {0}" + Environment.NewLine + Environment.NewLine, restoreTemp)); //Debug.WriteLine("Restoring to temp file - {0}", restoreTemp, null); FbRestore restore = new FbRestore() { ConnectionString = CreateConnectionString(restoreTemp), Verbose = true, Options = FbRestoreFlags.Create, }; restore.BackupFiles.Add(new FbBackupFile(source, null)); restore.ServiceOutput += ServiceOutput; //Program. try { restore.Execute(); } catch (ArgumentException ex) { MessageBox.Show(ex.Message); throw; // Удалить временный файл } //Debug.WriteLine("Restore complete - {0} ({1})", restoreTemp, GetFileSize(restoreTemp)); tb.AppendText(Environment.NewLine + "Переименование временного файла" + Environment.NewLine + Environment.NewLine); //Debug.WriteLine("Renaming temp restore file to - {0}", dest, null); File.Move(restoreTemp, dest); tb.AppendText(String.Format("Закончен процесс восстановления базы данных: {0}" + Environment.NewLine, DateTime.Now)); }
void BackupRestoreTest_RestorePart() { FbRestore restoreSvc = new FbRestore(); restoreSvc.ConnectionString = BuildServicesConnectionString(FbServerType); restoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace; restoreSvc.PageSize = TestsSetup.PageSize; restoreSvc.Verbose = true; restoreSvc.BackupFiles.Add(new FbBackupFile(TestsSetup.BackupRestoreFile, 2048)); restoreSvc.ServiceOutput += new EventHandler <ServiceOutputEventArgs>(ServiceOutput); restoreSvc.Execute(); }
public void RestoreTest() { FbRestore restoreSvc = new FbRestore(); restoreSvc.ConnectionString = this.BuildServicesConnectionString(); restoreSvc.BackupFiles.Add(new FbBackupFile(@"c:\testdb.gbk", 2048)); restoreSvc.Verbose = true; restoreSvc.PageSize = 4096; restoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace; restoreSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput); restoreSvc.Execute(); }
public void BackupRestore_B_Restore01Test() { FbRestore restoreSvc = new FbRestore(); restoreSvc.ConnectionString = BuildServicesConnectionString(); restoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace; restoreSvc.PageSize = 4096; restoreSvc.Verbose = true; restoreSvc.BackupFiles.Add(new FbBackupFile(ConfigurationManager.AppSettings["BackupRestoreFile"], 2048)); restoreSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput); restoreSvc.Execute(); // some validation }
public static void Restore(string DBFilePath, string BackupFilePath, string DbID, string DbPassword) { //db커낵션 확인후 커넥션 끊고 기존db파일 이름 바꿈 try { //커넥션 스트링 작성 FbConnectionStringBuilder fsb = new FbConnectionStringBuilder(); fsb.Database = DBFilePath; fsb.UserID = DbID; fsb.Password = DbPassword; fsb.ServerType = FbServerType.Embedded; //커넥션풀 클리어 FbConnection.ClearAllPools(); //원본 DB파일 이름 변경(원본파일 유지 해야 되니까) if (File.Exists(DBFilePath)) { string dbFolder = DBFilePath.Substring(DBFilePath.LastIndexOf("\\") + 1); string oldDbPath = string.Format ( "{0}\\old_{1}{2}{3}{4}{5}{6}.fdb", dbFolder, DBFilePath.Substring(DBFilePath.LastIndexOf("\\") + 1).Replace(".fdb", string.Empty), DateTime.Now.Year.ToString().Substring(2), DateTime.Now.Month.ToString().PadLeft(2, '0'), DateTime.Now.Day.ToString().PadLeft(2, '0'), DateTime.Now.Hour.ToString().PadLeft(2, '0'), DateTime.Now.Minute.ToString().PadLeft(2, '0') ); File.Move(DBFilePath, oldDbPath); } //백업 파일 객체 생성 FbBackupFile bkFile = new FbBackupFile(BackupFilePath); //위의 백업파일로부터 복구시작 FbRestore restore = new FbRestore(); restore.BackupFiles.Add(bkFile); restore.Options = FbRestoreFlags.Create; restore.ConnectionString = fsb.ToString(); restore.Execute(); } catch (Exception) { throw; } }
// public Boolean Restore(String p_path) { try { FbRestore mFbRestore = new FbRestore(C_Setting_DB.get_db_url()); mFbRestore.BackupFiles.Add(new FbBackupFile(p_path, 2048)); mFbRestore.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace; //mFbRestore.Verbose = true; //mFbRestore.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput); mFbRestore.Execute(); return(true); } catch (Exception e) { F_File.LogError(e); return(false); } }
public void Restore(string source, string dest) { if (!File.Exists(source)) { throw new FileNotFoundException("Source file not found", source); } if (File.Exists(dest)) { throw new IOException("Destination file already exists"); } Debug.WriteLine("Restoring database"); Debug.WriteLine("Source: {0} ({1})", source, GetFileSize(source)); Debug.WriteLine("Destination: {0}", dest, null); string restoreTemp = GetTempName(dest); Debug.WriteLine("Restoring to temp file - {0}", restoreTemp, null); FbRestore restore = new FbRestore() { ConnectionString = CreateConnectionString(restoreTemp), Verbose = true, Options = FbRestoreFlags.Create, }; restore.BackupFiles.Add(new FbBackupFile(source, null)); restore.ServiceOutput += ServiceOutput; restore.Execute(); Debug.WriteLine("Restore complete - {0} ({1})", restoreTemp, GetFileSize(restoreTemp)); Debug.WriteLine("Renaming temp restore file to - {0}", dest, null); File.Move(restoreTemp, dest); Debug.WriteLine("Done restore"); }
public void BackupRestoreTest() { var backupName = $"{Guid.NewGuid().ToString()}.bak"; void BackupPart() { var backupSvc = new FbBackup(); backupSvc.ConnectionString = BuildServicesConnectionString(FbServerType, Compression, WireCrypt, true); backupSvc.Options = FbBackupFlags.IgnoreLimbo; backupSvc.BackupFiles.Add(new FbBackupFile(backupName, 2048)); backupSvc.Verbose = true; backupSvc.Statistics = FbBackupRestoreStatistics.TotalTime | FbBackupRestoreStatistics.TimeDelta; backupSvc.ServiceOutput += ServiceOutput; backupSvc.Execute(); } void RestorePart() { var restoreSvc = new FbRestore(); restoreSvc.ConnectionString = BuildServicesConnectionString(FbServerType, Compression, WireCrypt, true); restoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace; restoreSvc.PageSize = FbTestsSetup.PageSize; restoreSvc.Verbose = true; restoreSvc.Statistics = FbBackupRestoreStatistics.TotalTime | FbBackupRestoreStatistics.TimeDelta; restoreSvc.BackupFiles.Add(new FbBackupFile(backupName, 2048)); restoreSvc.ServiceOutput += ServiceOutput; restoreSvc.Execute(); } BackupPart(); RestorePart(); // test the database was actually restored fine Connection.Open(); Connection.Close(); }
// Yedek yükleme public void YedekYukle(string GelenDizin) { try { FbRestore yedekYukle = new FbRestore(); yedekYukle.ConnectionString = baglanti_cumlesi; yedekYukle.BackupFiles.Add(new FbBackupFile(GelenDizin, 2048)); yedekYukle.Verbose = true; yedekYukle.PageSize = 8192; yedekYukle.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace; yedekYukle.Execute(); YedekYuklenmeTarihGuncelle(); MessageBox.Show("Seçilen yedek başarıyla yüklenmiştir.", "Yedekleme Bilgilendirme", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception h2) { MessageBox.Show(h2.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void BackupRestoreTest() { var backupName = $"{Guid.NewGuid().ToString()}.bak"; void BackupPart() { FbBackup backupSvc = new FbBackup(); backupSvc.ConnectionString = BuildServicesConnectionString(FbServerType, Compression, true); backupSvc.Options = FbBackupFlags.IgnoreLimbo; backupSvc.BackupFiles.Add(new FbBackupFile(backupName, 2048)); backupSvc.Verbose = true; backupSvc.ServiceOutput += new EventHandler <ServiceOutputEventArgs>(ServiceOutput); backupSvc.Execute(); } void RestorePart() { FbRestore restoreSvc = new FbRestore(); restoreSvc.ConnectionString = BuildServicesConnectionString(FbServerType, Compression, true); restoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace; restoreSvc.PageSize = TestsSetup.PageSize; restoreSvc.Verbose = true; restoreSvc.BackupFiles.Add(new FbBackupFile(backupName, 2048)); restoreSvc.ServiceOutput += new EventHandler <ServiceOutputEventArgs>(ServiceOutput); restoreSvc.Execute(); } BackupPart(); RestorePart(); // test the database was actually restored fine Connection.Open(); Connection.Close(); }
/// <summary> /// восстановить базу из резервной копии /// </summary> /// <param name="nameBackupFile">имя файла резервной копии</param> /// <returns>успешность</returns> public bool RestoreKl(string nameBackupFile) { bool result = true; if (System.IO.File.Exists(cs.Database)) { cs.Database = "C:\\OTG\\DB\\KL1.FDB"; } else { cs.Database = "C:\\OTG\\DB\\KL.FDB"; } FbRestore restoreSvc = new FbRestore(); restoreSvc.ConnectionString = cs.ToString(); restoreSvc.BackupFiles.Add(new FbBackupFile(nameBackupFile, 2048)); restoreSvc.Verbose = false; restoreSvc.PageSize = 4096; restoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace; restoreSvc.Execute(); cs.Database = "C:\\OTG\\DB\\KL.FDB"; return(result); }
private void btnRestaurarCopiaDeSeguranca_Click(object sender, EventArgs e) { OpenFileDialog ofdBackup = new OpenFileDialog(); this.Cursor = Cursors.WaitCursor; string NomeArquivo = string.Empty; FbConnection.ClearAllPools(); try { { ofdBackup.Title = "Abrir arquivo de BackUp"; ofdBackup.Filter = "Arquivo de Backup CRG 08|*.crg"; if (ofdBackup.ShowDialog(this) == DialogResult.OK) { if (ofdBackup.FileName != string.Empty) { NomeArquivo = ofdBackup.FileName; } else { MessageBox.Show("Selecione o backup para restaurar os dados", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { return; } } this.Cursor = Cursors.WaitCursor; string RestoreBanco = Environment.CurrentDirectory + "\\db.fdb"; //string conexao = @"User=SYSDBA;Password=masterkey;database = " + RestoreBanco + ";DataSource=localhost;Port=3050;Dialect=3;"; string conexao = Util.DAO.Conn; FbRestore RestoreSvc = new FbRestore(); RestoreSvc.ConnectionString = conexao; RestoreSvc.BackupFiles.Add(new FbBackupFile(NomeArquivo, 2048)); RestoreSvc.Verbose = true; RestoreSvc.PageSize = 4096; RestoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace; RestoreSvc.Execute(); MessageBox.Show("Backup restaurado com sucesso!", "Sucesso!", MessageBoxButtons.OK, MessageBoxIcon.Information); Application.Restart(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.Cursor = Cursors.Default; } }
private async Task RestoreAsync() { try { var databasePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Automatiza", "Instalador"); Directory.CreateDirectory(databasePath); OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = "Arquivo Firebird|databases.conf;aliases.conf" }; if (openFileDialog.ShowDialog() == true) { List <string> aliases = new List <string>(); var firebirdConf = File.ReadAllLines(openFileDialog.FileName); foreach (string line in firebirdConf) { if (line.Contains("Prolex")) { aliases.Add(line.Split(' ').FirstOrDefault()); } } foreach (string line in aliases) { try { var result = await Task.Run(() => { FbConnectionStringBuilder cs = new FbConnectionStringBuilder(); if (line.Equals("Prolex6", StringComparison.InvariantCultureIgnoreCase)) { DatabaseFile = Directory.GetFiles(databasePath, "Prolex6.prolexbkp").FirstOrDefault(); } else if (line.Equals("Prolex", StringComparison.InvariantCultureIgnoreCase)) { DatabaseFile = Directory.GetFiles(databasePath, "Prolex.prolexbkp").FirstOrDefault(); } cs.UserID = "SYSDBA"; cs.Password = "******"; cs.Database = line; FbRestore restoreSvc = new FbRestore(); restoreSvc.ConnectionString = cs.ToString(); restoreSvc.BackupFiles.Add(new FbBackupFile(DatabaseFile, 2048)); restoreSvc.Verbose = true; restoreSvc.PageSize = 4096; restoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace; restoreSvc.ServiceOutput += RestoreSvc_ServiceOutput; restoreSvc.Execute(); return(true); }); StatusLabel.Content = ""; progressBar.IsIndeterminate = false; /* * var titulo = "Aviso"; * var mensagem = $"Restauração do banco '{line}' concluído."; * var botoesConfig = MessageDialogStyle.Affirmative; * var dialogoConfig = new MetroDialogSettings() * { * AffirmativeButtonText = "OK" * }; * await this.ShowMessageAsync(titulo, mensagem, botoesConfig, dialogoConfig); */ MessageBox.Show($"Restauração do banco '{line}' concluído.", "Aviso", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //MessageBox.Show("Fase da restauração concluída","Aviso", MessageBoxButton.OK,MessageBoxImage.Information); Close(); } else { Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }