public static void doBackUp(BackUp obj, NotifyIcon notifyIcon_Main, List <BackUp> backUpList, string saveFile, DataGridView dtgrdvDisplay) { try { obj.objInit(); obj.pathToListAdd(obj.pathTo); DirectoryCopy(obj.pathFrom, obj.pathToList[obj.pathToList.Count - 1], true); notifyIcon_Main.BalloonTipTitle = "New Backup Created"; notifyIcon_Main.BalloonTipText = obj.descr + Environment.NewLine + "From:" + obj.pathFrom + Environment.NewLine + "To:" + obj.pathTo; notifyIcon_Main.ShowBalloonTip(500); obj.historyDateList.Add(DateTime.Now); obj.historyList.Add(new BackUpHistory(DateTime.Now, true, obj.size, obj.files, obj.folders)); obj.displayInit(); SaveBackUp(backUpList, saveFile); gridRefresh(backUpList, dtgrdvDisplay); } catch { } }
internal async Task <BackUp> BackUpDetails(SnapSession session) { try { ClientResponse <SnapBackupResponse> response = await this.SendRequestAsync <SnapBackupResponse>(Method.GET, $"api/3.0/backups?JobId={session.BackUpJobID}"); log.Info($"Payload Backup Detail: {response.Payload}"); BackUp theBackup = null; if (response.Payload.Backups != null) { //todo: check for the right one foreach (BackUp b in response.Payload.Backups) { theBackup = b; log.Info($"The Backup Detail: {theBackup.BackupId} {theBackup.BackupName}"); } } if (theBackup == null) { log.Info($"No backup details for jobid {session.BackUpJobID}"); } return(theBackup); } catch (Exception ex) { this.log.Error($"Error while getting backup details for job id {session.BackUpJobID}: {ex}"); throw; } }
public void CreateBackup(string aPath) { string lCopyFile = Path.Combine(FDataFolder.FullName, InstanceId + "_Copy" + ".exchange"); BackUp lBackUp = new BackUp(); string lBackupFile = Path.ChangeExtension(aPath, ".bkp"); string lSecret = Directory.EnumerateFiles(FDataFolder.FullName).Where((x) => x.Contains(InstanceId + ".secret")).ToList().First(); string lSettings = Directory.EnumerateFiles(FDataFolder.FullName).Where((x) => x.Contains(InstanceId + ".settings")).ToList().First(); string lExchange = Directory.EnumerateFiles(FDataFolder.FullName).Where((x) => x.Contains(InstanceId + ".exchange")).ToList().First(); File.Copy(lExchange, lCopyFile); lBackUp.Secret = File.ReadAllBytes(lSecret); lBackUp.LengthSecret = lBackUp.Secret.Length; lBackUp.Setting = File.ReadAllBytes(lSettings); lBackUp.LengthSetting = lBackUp.Setting.Length; lBackUp.Exchange = File.ReadAllBytes(Path.Combine(FDataFolder.FullName, InstanceId + "_Copy" + ".exchange")); lBackUp.LengthExchange = lBackUp.Exchange.Length; lBackUp.Version = 112; if (File.Exists(lBackupFile)) { File.Delete(lBackupFile); WriteBackupFile(lBackupFile, lBackUp); } else { WriteBackupFile(lBackupFile, lBackUp); } File.Delete(lCopyFile); }
private void RestoreClone(SnapSession snapSession) { Task.Run(async() => { log.Info($"Trying to restore DB for application {snapSession.AppName}. SnapSession: {snapSession.toString()}"); SnapCenter snapClient = await SnapCenter.NewSnapCenterSession(snapSession); BackUp b = snapClient.GetCloneSnapshot(snapSession); this.log.Info($"GetCloneSnapshot existed and b is not null: {b != null}"); if (b != null) { //restore snapshot snapSession.BackupName = b.BackupName; string answer = await snapClient.RestoreClone(snapSession); this.log.Info($"Clone restore complete. Response: {answer}"); } else { this.log.Info($"No snapshots found proceding to cloning the original."); await snapClient.CloneOriginal(snapSession); string snapshotID = await snapClient.SnapshotClone(snapSession); this.log.Info($"Clone backup complete. ID: {snapshotID}"); } }).GetAwaiter().GetResult(); }
public static void AddExtraTime(BackUp obj) { switch (obj.Mode) { case 0: obj.AddWeeks(obj.ModeValue); break; case 1: obj.AddDays(obj.ModeValue); break; case 2: obj.AddHours(obj.ModeValue); break; case 3: obj.AddMinutes(obj.ModeValue); break; case 4: obj.AddSeconds(obj.ModeValue); break; case 5: obj.AddSeconds(0); break; } }
public async Task<IActionResult> Crear([FromBody] BackUp item) { try { var r = await this.Repositorio.BackUps.AddAsync(item); await this.Repositorio.CompleteAsync(); var obj = new { ok = true, BackUp = r }; return Created("", obj); } catch (Exception ex) { return BadRequest(new { ok = false, mensaje = "Se produjo un error al crear el registro", errors = new { mensaje = ex.Message } }); } }
private void RestoreB_Click(object sender, RoutedEventArgs e) { if (ENKT.Text != "") { if (BackUpList.SelectedIndex != -1) { BackUp.Restore(PathT.Text + BackUpList.SelectedItem, ENKT.Text); } else { MessageBox.Show("اختر نسخه اولا ليتم استعادتها "); } } else { if (BackUpList.SelectedIndex != -1) { BackUp.Restore(PathT.Text + BackUpList.SelectedItem, "PROPHMW"); } else { MessageBox.Show("اختر نسخه اولا ليتم استعادتها "); } } }
private void btn_BackUp_Click(object sender, EventArgs e) { BackUp bk = new BackUp(fromPath.SelectedPath, toPath.SelectedPath, txtbJob.Text, DateTime.Now, cbxList[cbx_Mode.SelectedIndex].Mode, (int)nmr_Repeat.Value, cbxList[cbx_Mode.SelectedIndex].Descr); backUpList.Add(bk); doBackUp(bk); }
public bool RestoreInformationFromFile(string aPath) { FUserSettings.DeleteSettings(); BackUp lBackup = new BackUp(); string lPathSecret = Path.Combine(FDataFolder.FullName, InstanceId + ".secret"); string lPathSettings = Path.Combine(FDataFolder.FullName, InstanceId + ".settings"); string lPathExchange = Path.Combine(FDataFolder.FullName, InstanceId + ".exchange"); using (FileStream lFileStream = new FileStream(aPath, FileMode.Open, FileAccess.Read)) { using (BinaryReader lBinaryReader = new BinaryReader(lFileStream)) { lBackup.Version = lBinaryReader.ReadInt32(); lBackup.LengthSecret = lBinaryReader.ReadInt32(); lBackup.Secret = lBinaryReader.ReadBytes(lBackup.LengthSecret); lBackup.LengthSetting = lBinaryReader.ReadInt32(); lBackup.Setting = lBinaryReader.ReadBytes(lBackup.LengthSetting); lBackup.LengthExchange = lBinaryReader.ReadInt32(); lBackup.Exchange = lBinaryReader.ReadBytes(lBackup.LengthExchange); } } if (File.Exists(lPathSecret)) { File.Delete(lPathSecret); } using (FileStream lFileStream = new FileStream(lPathSecret, FileMode.Create, FileAccess.Write)) { using (BinaryWriter lBinaryWriter = new BinaryWriter(lFileStream)) { lBinaryWriter.Write(lBackup.Secret); } } if (File.Exists(lPathSettings)) { File.Delete(lPathSettings); } using (FileStream lFileStream = new FileStream(lPathSettings, FileMode.Create, FileAccess.Write)) { using (BinaryWriter lBinaryWriter = new BinaryWriter(lFileStream)) { lBinaryWriter.Write(lBackup.Setting); } } if (File.Exists(lPathExchange)) { File.Delete(lPathExchange); } using (FileStream lFileStream = new FileStream(lPathExchange, FileMode.Create, FileAccess.Write)) { using (BinaryWriter lBinaryWriter = new BinaryWriter(lFileStream)) { lBinaryWriter.Write(lBackup.Exchange); } } FUserSettings.LoadSettings(); return(true); }
protected void btnRestoreBD_Click(object sender, EventArgs e) { try { sinBackup.Visible = false; if (dpBackUps.Items == null || dpBackUps.Items.Count <= 0) { sinBackup.Visible = true; return; } var seguridad = new SeguridadBLL(); var bk = new BackUp() { BackUpPath = Server.MapPath("~/BackUps/"), NombreBD = dpBackUps.SelectedItem.Text }; bool res = seguridad.RestoreBD(bk); divError.Visible = !res; divExito.Visible = res; } catch (Exception) { sinBackup.Visible = true; } }
private void btn_BackUp_Click(object sender, EventArgs e) { bk = new BackUp(fromPath.SelectedPath, toPath.SelectedPath, txtbJob.Text, DateTime.Now, cbxList[cbx_Mode.SelectedIndex].Mode, (int)nmr_Repeat.Value, cbxList[cbx_Mode.SelectedIndex].Descr); backUpList.Add(bk); //firstBackup = true; Tools.doBackUp(bk, notifyIcon_Main, backUpList, saveFile, dtgrdvDisplay); BackUp.AddExtraTime(bk); }
protected bool IsBackUpUse(BackUp backUp) { if ((DateTime.Now - backUp.LastUse).Seconds > 60) { return(false); } return(true); }
public void BackUp() { SQLParser par = new SQLParser(); BackUp sbres = (BackUp)par.Parser("BACKUP DATABASE database TO DISK = 'filepath';"); BackUp backup = new BackUp("database", "filepath"); Assert.AreEqual(sbres.GetType(), backup.GetType()); Assert.AreEqual(sbres.getDB(), backup.getDB()); }
private void btnBackUp_Click(object sender, EventArgs e) { if (BackUp.realizarBackUp(Sesion.obtenerSesion().usuario)) { label1.Text = Sesion.obtenerSesion().idioma.textos["bkp_done"]; } else { label1.Text = Sesion.obtenerSesion().idioma.textos["error"]; } }
private void smnCargarBD_Click(object sender, EventArgs e) { BackUp oBackup = new BackUp(); bool blnRespuesta = oBackup.Cargar(); if (blnRespuesta == true) { MessageBox.Show("Se ha cargado la nueva base de datos", "Carga de base de datos", MessageBoxButtons.OK, MessageBoxIcon.Information); frmHome frmHome1 = new frmHome(); MostrarForm(frmHome1); } }
public int CountRestorePointsForCleaning(BackUp backUp) { var result = 0; var backUpSize = backUp.Size(); foreach (var storage in backUp.BackUpComponents.Where(storage => backUpSize > ClearingSize)) { result++; backUpSize -= storage.Size(); } return(result); }
private void smnBackUp_Click(object sender, EventArgs e) { BackUp oBackup = new BackUp(); bool blnRespuesta = oBackup.Resguardar(); if (blnRespuesta == true) { MessageBox.Show("La copia de seguridad se realizó con éxito", "Copia de seguridad", MessageBoxButtons.OK, MessageBoxIcon.Information); frmHome frmHome1 = new frmHome(); MostrarForm(frmHome1); } }
private BackUp FindSnapshot(SnapSession snapSession) { BackUp b = null; Task.Run(async() => { this.log.Info($"Obtaining DB key {snapSession.DbName}."); SnapCenter snapClient = await SnapCenter.NewSnapCenterSession(snapSession); b = snapClient.GetCloneSnapshot(snapSession); }).GetAwaiter().GetResult(); return(b); }
//database private void SetB1_Click(object sender, RoutedEventArgs e) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { BackUp.NewDbBackup(); MessageBox.Show("تم اخذ نسخه احتياطيه من القاعده القديمه"); DataHolder.CreateConnection(co.DbUserName, co.DbUserPassword, co.Hostname); CreateDB.Createdb(co.DbName, DbName.Text); co.Write(); MessageBox.Show("تم الحفظ سيتم غلق البرنامج الان"); Environment.Exit(0); }); }
private static void RemoveLastRestorePoint(BackUp backUp) { try { var firstPoint = backUp.Manager.RestorePoints.Dequeue(); backUp.BackUpComponents.Remove(firstPoint.Storage.Build()); firstPoint.Storage.RemoveAll(); } catch { throw new FileRemoveException(); } }
public override async void ClearRestorePoint(BackUp backUp) { await Task.Run(() => { while (!Stop && IsBackUpUse(backUp)) { if (IsSizeTrue(backUp, ClearingSize) && backUp.Manager.RestorePoints.Any()) { RemoveLastRestorePoint(backUp); } } }); }
private void FindResultCleaning(BackUp backUp) { AddAvailableLimits(); if (_type == ComboType.Max) { _resultClearing = FindMaxCleaning(backUp); } if (_type == ComboType.Min) { _resultClearing = FindMinCleaning(backUp); } }
private void RestoreB_Click(object sender, EventArgs e) { if (EncryptionKey.Text != "") { CheckForIllegalCrossThreadCalls = false; Thread th2 = new Thread(() => BackUp.Restore(BPath.Text + BackUpList.SelectedItem, EncryptionKey.Text)); th2.Start(); } else { MessageBox.Show("اختر مفتاح تشفير بالانجلزيه و احفظه جيدا لانك ستحتاجه فى كل مرة تحفظ او تسترجع نسخة احتياطيه"); } }
private void Install_Click(object sender, EventArgs e) { try { IniFile file = new IniFile(Constants.SetupConfigPath); if (this.Text == "تنصيب البرنامج") { if (!File.Exists(Constants.SetupConfigPath)) { file.Write("MySql", "Host", DBHost.Text); file.Write("MySql", "Username", DBUser.Text); file.Write("MySql", "Password", DBPass.Text); file.Write("MySql", "Database", DBName.Text); file.Write("Upgrade", "Version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString().Replace(".", "")); if (!Directory.Exists(Application.StartupPath + @"BackUp\")) { Directory.CreateDirectory(Application.StartupPath + @"\BackUp\"); } DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); CreateDB.Createdb(DBName.Text); DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Database")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); CreateDB.CreateTables(); MessageBox.Show("تم تنصيب الاعدادات\nمن فضلك انشاء حساب جديد لتتمكن من الدخول"); Register reg = new Register(); reg.ShowDialog(); this.Close(); } } else if (this.Text == "اعدادات البرنامج") { if (File.Exists(Constants.SetupConfigPath)) { BackUp.NewDbBackup(); DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); CreateDB.Createdb(file.ReadString("MySql", "Database"), DBName.Text); file.Write("MySql", "Host", DBHost.Text); file.Write("MySql", "Username", DBUser.Text); file.Write("MySql", "Password", DBPass.Text); file.Write("MySql", "Database", DBName.Text); DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Database")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); BackUp.NewDbRestore(); BillsTable.LBN(); MessageBox.Show("تم تغيير الاعدادات"); } } } catch (Exception ee) { Program.SaveException(ee); } }
private void enableBackups() { foreach (BackUp bk in backUpList) { if (bk.Mode != 5) { while (DateTime.Compare(bk.Date, DateTime.Now) < 0) { bk.historyList.Add(new BackUpHistory(bk.Date, false, 0, 0)); BackUp.AddExtraTime(bk); } } } }
private void btnRestore_Click(object sender, EventArgs e) { openFileDialog1 = new OpenFileDialog { Filter = "Database backups (*.bak)|*.bak", Title = "Open database backup", InitialDirectory = Directory.GetCurrentDirectory() + "\\..\\..\\..\\BackUps\\", }; if (openFileDialog1.ShowDialog() == DialogResult.OK) { BackUp.realizarRestore(openFileDialog1.FileName, Sesion.obtenerSesion().usuario); lblResponse.Text = Sesion.obtenerSesion().idioma.textos["restore_done"]; } }
private void BackUpB_Click(object sender, RoutedEventArgs e) { if (ENKT.Text != "") { BackUp.Backup(ENKT.Text); CountBacks++; Count.Content = "عدد النسخ الاحتياطية : " + CountBacks; } else { BackUp.Backup("PROPHMW"); CountBacks++; Count.Content = "عدد النسخ الاحتياطية : " + CountBacks; } Reload(); }
public void WriteBackupFile(string aPath, BackUp aBackUp) { using (FileStream lFileStream = new FileStream(aPath, FileMode.Create, FileAccess.Write)) { using (BinaryWriter lBinaryWriter = new BinaryWriter(lFileStream)) { lBinaryWriter.Write(aBackUp.Version); lBinaryWriter.Write(aBackUp.LengthSecret); lBinaryWriter.Write(aBackUp.Secret); lBinaryWriter.Write(aBackUp.LengthSetting); lBinaryWriter.Write(aBackUp.Setting); lBinaryWriter.Write(aBackUp.LengthExchange); lBinaryWriter.Write(aBackUp.Exchange); } } }
private Interfaces.RestorePointClearing FindMinCleaning(BackUp backUp) { var minCount = int.MaxValue; Interfaces.RestorePointClearing minCleaning = null; foreach (var limit in _availableLimits) { var count = limit.CountRestorePointsForCleaning(backUp); if (count < minCount) { minCount = count; minCleaning = limit.ToRestore(); } } return(minCleaning); }
public async Task<IActionResult> Actualizar([FromBody] BackUp itemNuevo, int id) { try { itemNuevo.Id = id; var itemEncontrado = await this.Repositorio.BackUps.GetByIdAsync(id); if (itemEncontrado == null) { return BadRequest(new { ok = false, mensaje = "No se encontró el registro a actulizar", erros = "" }); } itemEncontrado.Map(itemNuevo); var r = this.Repositorio.BackUps.Update(itemEncontrado); await this.Repositorio.CompleteAsync(); var obj = new { ok = true, BackUp = itemEncontrado }; return Created("", obj); } catch (Exception ex) { return BadRequest(new { ok = false, mensaje = "Se produjo un error al Actualizar el registro", errors = new { mensaje = ex.Message } }); } }