private void buttonX1_Click(object sender, EventArgs e) { if (Program.ISSaDmin) { constr = Program.Str_con; OpenFileDialog of = new OpenFileDialog(); of.Multiselect = false; if (of.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } else { mb = new MySqlBackup(constr); mb.ImportInfo.EncryptionKey = "Harrazi"; mb.ImportInfo.EnableEncryption = true; mb.ImportInfo.FileName = of.FileName; TimerImport = new Timer(); TimerImport.Interval = 10; TimerImport.Tick += new EventHandler(TimerImport_Tick); TimerImport.Start(); mb.ImportProgressChanged += new MySqlBackup.importProgressChange(mb_ImportProgressChanged); mb.ImportInfo.SetTargetDatabase("commerce", "utf8"); mb.Import(); } } else { MessageBox.Show("Accés Non Autorisé"); } }
private void btImport_Click(object sender, EventArgs e) { OpenFileDialog of = new OpenFileDialog(); of.Multiselect = false; if (of.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } mb = new MySqlBackup(constr); mb.ImportInfo.AsynchronousMode = cbImAsyn.Checked; mb.ImportInfo.AutoCloseConnection = cbImAutoCloseConnection.Checked; mb.ImportInfo.EnableEncryption = cbImEnableEncrypt.Checked; mb.ImportInfo.EncryptionKey = txtImEncryptKey.Text; mb.ImportInfo.FileName = of.FileName; mb.ImportInfo.IgnoreSqlError = cbImIgnoreSqlError.Checked; string newCharSet = ""; if (cbCharSet.SelectedIndex > 0) { newCharSet = cbCharSet.Text; } mb.ImportInfo.SetTargetDatabase(txtTargetDatabase.Text, newCharSet); if (cbImAsyn.Checked) { TimerImport = new Timer(); TimerImport.Interval = 10; TimerImport.Tick += new EventHandler(TimerImport_Tick); TimerImport.Start(); TimerStopImport = new Timer(); TimerStopImport.Interval = 100; TimerStopImport.Tick += new EventHandler(TimerStopImport_Tick); mb.ImportProgressChanged += new MySqlBackup.importProgressChange(mb_ImportProgressChanged); mb.ImportCompleted += new MySqlBackup.importComplete(mb_ImportCompleted); } try { mb.Import(); if (!cbImAsyn.Checked) { ShowImportCompleteMessage(mb.ImportInfo.CompleteArg); } } catch { ShowImportCompleteMessage(mb.ImportInfo.CompleteArg); } }
private void restaurarToolStripMenuItem1_Click(object sender, EventArgs e) { if (MessageBox.Show("Estas seguro de abrir un archivo de respaldo? se remplazara toda la información en el sistema con lo que existe en el archivo de respaldo", "Confirm delete", MessageBoxButtons.YesNo) == DialogResult.Yes) { //se abre la ventana para seleccionar acrhivo OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "Archivos de sql (*.sql)|*.sql"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { //se abre el respaldo try { string constr = "server=localhost;User Id=root;Persist Security Info=True;database=gym"; string file = openFileDialog1.FileName; MySqlBackup mb = new MySqlBackup(constr); mb.ImportInfo.FileName = file; mb.ImportInfo.SetTargetDatabase("gym", ImportInformations.CharSet.utf8); mb.Import(); } catch (Exception ex) { MessageBox.Show("Ocurrió un error " + ex.Message); } } catch (Exception ex) { MessageBox.Show("Error del Sistema: " + ex.Message); } } MessageBox.Show("Información restaurada con éxito"); //se cierran formularios cerrarFormuarios(); //se cierra sesion if (Utilidades.clsUsuario.salir()) { sinSesion(); } else { MessageBox.Show(Utilidades.clsUsuario.error); } } }
private void btRestore_Click(System.Object sender, System.EventArgs e) { OpenFileDialog oof = new OpenFileDialog(); oof.Multiselect = false; if (oof.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } ProgressBar1.Value = 0; timerRead.Start(); mb.Connection = new MySqlConnection(txtConstr.Text); mb.ImportInfo.AsynchronousMode = true; mb.ImportInfo.FileName = oof.FileName; mb.Import(); }
private void radButtonRestore_Click(object sender, EventArgs e) { try { if (radCheckEnkripsi.Checked == true) { try { string file = openFileDialog1.FileName; string conn = "server=localhost;user=root;database=administrasi;"; MySqlBackup mb = new MySqlBackup(conn); mb.ImportInfo.FileName = file; mb.ImportInfo.EnableEncryption = true; mb.ImportInfo.EncryptionKey = radTextPassword.Text; mb.Import(); MessageBox.Show("Berhasil Restore Database", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch { MessageBox.Show("Password Salah", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { try { string file = openFileDialog1.FileName; string conn = "server=localhost;user=root;database=administrasi;"; MySqlBackup mb = new MySqlBackup(conn); mb.ImportInfo.FileName = file; mb.Import(); MessageBox.Show("Berhasil Restore Database", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch { MessageBox.Show("Database ter-Enkripsi", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { MessageBox.Show("Masukkan lokasi simpan database", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected void Page_Load(object sender, EventArgs e) { GlobalMethods.DeleteOldFile(); if (Session["connectionstring"] == null || Session["dumpfile"] == null) { Response.Redirect("~/Default.aspx", true); } else { MySqlBackup mb = null; Exception ex1 = null; try { mb = new MySqlBackup(Session["connectionstring"].ToString()); mb.ImportInfo.FileName = Session["dumpfile"].ToString(); mb.Import(); } catch (Exception ex2) { ex1 = ex2; } System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("Restore " + mb.ImportInfo.CompleteArg.CompletedType + "<br />"); sb.Append("Time Start: " + mb.ImportInfo.CompleteArg.TimeStart + "<br />"); sb.Append("Time End: " + mb.ImportInfo.CompleteArg.TimeEnd + "<br />"); sb.Append("Time Used: " + mb.ImportInfo.CompleteArg.TimeUsed.Seconds + " s " + mb.ImportInfo.CompleteArg.TimeUsed.Milliseconds + " ms<br />"); if (mb.ImportInfo.CompleteArg.HasErrors) { sb.Append("Displaying Last Error:<br /><br />" + ex1 + "<br /><br />"); } Session["resultmsg"] = sb.ToString(); Response.Redirect("~/RestoreComplete.aspx", true); } }
public static async Task Restore(this MySqlDatabase db, string inputFile, IProgress <int> progress, CancellationToken token) { await db.ExecuteScript("SET GLOBAL max_allowed_packet = 1024*1024*1024;"); await Task.Run(() => { using (var backup = new MySqlBackup(db.ConnectionString)) { var tcs = new TaskCompletionSource <bool>(); backup.ImportInfo.FileName = inputFile; backup.ImportInfo.AsynchronousMode = true; backup.ImportInfo.AutoCloseConnection = true; backup.ImportInfo.IgnoreSqlError = true; backup.Import(); backup.ImportProgressChanged += (sender, e) => progress.Report(e.PercentageCompleted); backup.ImportCompleted += (sender, e) => tcs.SetResult(true); tcs.Task.Wait(); } }); }