Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string ip        = System.IO.File.ReadAllText("docs\\ip.txt");
                string db        = database1.Text;
                string username  = "******";
                string password  = "******";
                string constring = "server=" + ip + ";user="******";pwd=" + password + ";database=" + db + ";";

                string mytime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString();
                string file   = Environment.CurrentDirectory + "\\back_ups\\" + mytime + ".sql";
                string file1  = " ";
                using (MySqlConnection conn = new MySqlConnection(constring))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();
                            file1 = file;
                            if (!File.Exists(Environment.CurrentDirectory + "\\back_ups\\" + mytime + ".sql"))
                            {
                                int fCount = Directory.GetFiles(Environment.CurrentDirectory + "\\back_ups\\", "*", SearchOption.TopDirectoryOnly).Length;
                                if (fCount < 30)
                                {
                                    mb.ExportToFile(file1);
                                }
                                else
                                {
                                    DateTime dateForButton = DateTime.Now.AddDays(-30);
                                    MessageBox.Show("Date for delete " + dateForButton.ToString());
                                    MessageBox.Show(Environment.CurrentDirectory);
                                    File.Delete(Environment.CurrentDirectory + "\\back_ups\\" + dateForButton.Day.ToString() + "-" + dateForButton.Month.ToString() + "-" + dateForButton.Year.ToString() + ".sql");
                                    mb.ExportToFile(file1);
                                }
                            }

                            conn.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception Occured " + ex);
            }
        }
Exemple #2
0
        public static bool MakeBackup(string pRuta)
        {
            bool result = true;

            try
            {
                using (MySqlConnection _con = new Conexion().Conectar())
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = _con;
                            _con.Open();
                            mb.ExportToFile(pRuta);
                            _con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                throw ex;
            }
            finally
            {
            }
            return(result);
        }
Exemple #3
0
 private void metroButton6_Click(object sender, EventArgs e)
 {
     
                 saveFileDialog1.Filter = "Text files (*.bak)|*.bak|All files (*.*)|*.*";
                 if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                 {
                     string constring = "SERVER=localhost;DATABASE=Silvercity;UID=root;PASSWORD=smhs;";
                     string file = saveFileDialog1.FileName;
                     using (MySqlConnection conn = new MySqlConnection(constring))
                     {
                         using (MySqlCommand cmd = new MySqlCommand())
                         {
                             using (MySqlBackup mb = new MySqlBackup(cmd))
                             {
                                 cmd.Connection = conn;
                                 conn.Open();
                                 mb.ExportToFile(file);
                                 conn.Close();
                             }
                         }
                     }
                     MetroMessageBox.Show(this, "\nDatabase BackUp has been created successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     Application.OpenForms["Home"].BringToFront();
                     Application.OpenForms["Set"].BringToFront();
                 }
     
 }
        public int BackupBaseDatos()
        {
            using (MySqlDatabase conn = new MySqlDatabase())
            {
                using (MySqlBackup bac = new MySqlBackup())
                {
                    bac.ExportToFile("PRUEBA-CHIDA.sql");
                }
            }



            /*
             * using (MySqlConnection conn = new MySqlConnection(connectionString))
             * {
             *
             *  using (MySqlCommand cmd = new MySqlCommand())
             *  {
             *
             *
             *      using (MySqlBackup bac = new MySqlBackup(cmd)) {
             *
             *          bac.ExportToFile("C:\\Users\\eduar\\Desktop\\PRUEBA-CHIDA.sql");
             *      }
             *
             *  }
             *
             *
             * }*/

            return(1);
        }
Exemple #5
0
        private void btExport_Click(object sender, EventArgs e)
        {
            if (!Program.TargetDirectoryIsValid())
            {
                return;
            }

            try
            {
                using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();

                            mb.ExportToFile(Program.TargetFile);

                            conn.Close();
                        }
                    }
                }

                MessageBox.Show("Done.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemple #6
0
        private void exportarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog caminho = new SaveFileDialog();

            caminho.FileName   = "Backup";
            caminho.DefaultExt = ".sql";
            caminho.Filter     = "Todos os Aquivos de banco (*.sql)|*.sql| Todos os arquivos (*.*)|*.*";
            if (caminho.ShowDialog() == DialogResult.OK)
            {
                //string constring = "Persist Security Info=false;SERVER=localhost;DATABASE=escalada;UID=root;pwd=";
                using (MySqlConnection conn = new MySqlConnection(sc.Endereco()))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            string dest = caminho.FileName;
                            cmd.Connection = conn;
                            conn.Open();
                            mb.ExportToFile(dest);
                            conn.Close();
                            string      msg = "Backup exportado com sucesso!!!";
                            frmMensagem mg  = new frmMensagem(msg);
                            mg.ShowDialog();
                        }
                    }
                }
            }
        }
Exemple #7
0
        public bool Backup(string caminho)
        {
            try {
                String connString = ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ToString();

                string file = caminho + "\\BancoDeDados " + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".sql";

                using (MySqlConnection conn = new MySqlConnection(connString))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();

                            mb.ExportInfo.AddCreateDatabase = true;
                            mb.ExportToFile(file);
                            conn.Close();
                        }
                    }
                }

                isOK = true;
            } catch (Exception e) {
                isOK = false;
                throw e;
            }


            return(isOK);
        }
        public static async Task BackupDatabase()
        {
            HitException = null;
            var backuplocation = SettingsFile.databasebackuplocation.Replace("DATETIME", DateTime.Now.ToString("yyyy'-'MM'-'dd'_'HH'-'mm'-'ss"));

            using (MySqlConnection con = new MySqlConnection(ConnectionString))
            {
                try
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = con;
                            await con.OpenAsync();

                            mb.ExportToFile(backuplocation);
                        }
                    }
                }
                catch (Exception ex)
                {
                    HitException = ex;
                }
                finally
                {
                    await con.CloseAsync();
                }
            }
            return;
        }
Exemple #9
0
 public void Export(string mfile, MySqlBackup.exportComplete OnDone, EventHandler <MySqlBackup.ExceptionEventArgs> onError, MySqlBackup.exportProgressChange onProgress)
 {
     Task.Factory.StartNew(() =>
     {
         try
         {
             using (MySqlCommand cmd = new MySqlCommand())
             {
                 cmd.Connection = new MySqlConnection(mArgs.GetConnectionString());
                 cmd.Connection.Open();
                 using (MySqlBackup bck = new MySqlBackup(cmd))
                 {
                     bck.ExportProgressChanged += onProgress;
                     bck.ExportCompleted       += OnDone;
                     bck.ExportToFile(mfile);
                 }
             }
         }
         catch (Exception ex)
         {
             onError(this, new MySqlBackup.ExceptionEventArgs()
             {
                 ex = ex
             });
         }
     });
 }
        // Database backup method.
        private void databaseBackUp()
        {
            try
            {
                dialog = MessageBox.Show("Are you sure you want to back up the database?", "DATABASE BACKUP", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dialog == DialogResult.Yes)
                {
                    string file = "C:\\pos\\Data\\backup.sql";

                    using (MySqlConnection con = new MySqlConnection(databaseConnection))
                    {
                        using (MySqlCommand command = new MySqlCommand())
                        {
                            using (MySqlBackup backup = new MySqlBackup(command))
                            {
                                command.Connection = con;
                                con.Open();
                                backup.ExportToFile(file);
                                con.Close();
                            }
                        }
                    }
                    MessageBox.Show("Database backup successful...............!", "DATABASE BACKUP", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error has occured while backing up database ............!", "DATABASE BACKUP ERROR", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
            }
        }// End backup of database.
        public bool exportar(String ruta)
        {
            cargarDatosRegistro();
            string constring = "server=" + server + ";user="******";pwd=" + contra + ";database=" + dbase + ";";
            string file      = ruta;

            using (MySqlConnection conn = new MySqlConnection(constring))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        try
                        {
                            cmd.Connection = conn;
                            conn.Open();
                            mb.ExportToFile(file);
                            mb.ImportInfo.DatabaseDefaultCharSet = "latin1";
                            conn.Close();
                            return(true);
                        }
                        catch
                        {
                            return(false);
                        }
                    }
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.DefaultExt = "sql";

            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    string constring = "server=localhost;user=root;pwd=;database=AutoStereoDavao;SslMode=none;";

                    using (MySqlConnection conn = new MySqlConnection(constring))
                    {
                        using (MySqlCommand cmd = new MySqlCommand())
                        {
                            using (MySqlBackup mb = new MySqlBackup(cmd))
                            {
                                cmd.Connection = conn;
                                conn.Open();
                                mb.ExportToFile(saveFileDialog1.FileName);
                                conn.Close();
                            }
                        }
                    }
                }
                catch (Exception E) { System.Windows.MessageBox.Show(E.Message); return; }
                System.Windows.MessageBox.Show("Back-up Data Successfully created!");
            }
        }
Exemple #13
0
        private void respaldo()
        {
            try
            {
                string cadena;
                cadena = "cmd.exe /k " + rutaDump + " -h 192.168.1.103 -u prueba -p1532  prod > " + destino;

                MySqlCommand com = new MySqlCommand();
                conect.iniciar();
                com.Connection = conect.conn;
                MySqlBackup respaldo = new MySqlBackup(com);
                // MessageBox.Show(cadena)
                //   Shell(cadena, 0);
                conect.conn.Open();
                respaldo.ExportToFile(destino);
                conect.conn.Close();

                MessageBox.Show("El respaldo se ha realizado con exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TxtRuta.Clear();
            }
            catch (Exception ex)
            {
                conect.conn.Close();
                MessageBox.Show(ex.ToString());
                TxtRuta.Clear();
            }
        }
Exemple #14
0
        public void backup()
        {
            MySqlCommand mySql = new MySqlCommand();

            mySql.Connection = conn;

            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }

            MySqlBackup  backup = new MySqlBackup(mySql);
            var          folderBrowserDialog1 = new FolderBrowserDialog();
            DialogResult result = folderBrowserDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                string folderName = folderBrowserDialog1.SelectedPath;
                try
                {
                    backup.ExportToFile(folderName + "MySqlDataBase.sql");
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.ToString());
                    MessageBox.Show("Error!");
                }
            }
        }
Exemple #15
0
 public void Backup()
 {
     try
     {
         string constring = "server=localhost;user=root;database=bookingdb;pooling = false;convert zero datetime=True";
         string file      = "C:\\backupBookingSql.sql";
         using (MySqlConnection conn = new MySqlConnection(constring))
         {
             using (MySqlCommand cmd = new MySqlCommand())
             {
                 using (MySqlBackup mb = new MySqlBackup(cmd))
                 {
                     cmd.Connection = conn;
                     conn.Open();
                     mb.ExportToFile(file);
                     conn.Close();
                 }
             }
         }
     }
     catch (Exception err)
     {
         Console.WriteLine(err.Message);
     }
 }
        private void Backup(String RutaGuardada)
        {
            //Los parametros de la base de datos para hacer el backup
            string constring = "server=localhost;user=root;pwd=123456;database=ucs_bd;";

            // decidir el unicode y convertir fechas nulas en 0 para evitar errores (cosas de MySQL que no acepta como nulas)
            constring += "charset=utf8;convertzerodatetime=true;";


            //Se abre la conexion con el caracter unicode utf8 y los parametros de la base de datos
            using (MySqlConnection conn = new MySqlConnection(constring))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();

                        //Se exportan las tablas de la bd en el archivo creado por la ruta que selecciona el usuario

                        mb.ExportToFile(RutaGuardada);
                        conn.Close();
                        MessageBox.Show("Respaldo creado exitosamente.");
                    }
                }
            }
        }
Exemple #17
0
        public static void BackUp()
        {
            CheckConnection();
            DialogResult result = data.SaveSQL.ShowDialog();
            string       file   = data.SaveSQL.FileName;

            if (result == DialogResult.OK)
            {
                try
                {
                    MySqlCommand cmd = new MySqlCommand();
                    MySqlBackup  bk  = new MySqlBackup(cmd);
                    cmd.Connection = connection;
                    bk.ExportToFile(file);
                    connection.Close();
                    MessageBox.Show("Export Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (MySqlException ex)
                {
                    logForm.addText(ex.Message + "\n", Color.Red);
                    ErrorForm.MessageError.Text = ex.Message;
                    ErrorForm.ShowDialog();
                }
            }
        }
Exemple #18
0
 public static void backupData()
 {
     try
     {
         string constring = "server=localhost;user=root;pwd='';database=essentialmode;SslMode=none;charset=latin5;";
         string fileName  = String.Format("{0:d/M/yyyy HH/mm/ss}", DateTime.Now);
         string file      = Application.StartupPath + "(" + fileName + ").sql";
         using (MySqlConnection conn = new MySqlConnection(constring))
         {
             using (MySqlCommand cmd = new MySqlCommand())
             {
                 using (MySqlBackup mb = new MySqlBackup(cmd))
                 {
                     cmd.Connection = conn;
                     conn.Open();
                     mb.ExportToFile(file);
                     conn.Close();
                 }
             }
         }
         logText("Mysql Yedeklendi.");
         AutoClosingMessageBox.Show("Yedek Alındı.", "Mysql", 500);
     }
     catch (Exception)
     {
         logText("Mysql HATA.");
         AutoClosingMessageBox.Show("Mysql Yedeği Alınamadı. Lütfen Yedek Klasörünün Olduğundan Emin Olunuz.", "", 500);
     }
 }
Exemple #19
0
        private void btnBackUp_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            if (saveFileDialog.ShowDialog() == true)
            {
                File.WriteAllText(saveFileDialog.FileName, debugLog.Text);
            }

            string file = saveFileDialog.FileName;

            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        mb.ExportToFile(file);
                        conn.Close();
                    }
                }
            }


            MessageBox.Show("Back Up successful");
        }
Exemple #20
0
        private void btnBackup_Click(object sender, EventArgs e)
        {
            t.Start();

            try
            {
                lblfilePath.Text = path + @"\dhanushka\backup\" + FileName + "";
                MySqlConnection cnnection = new MySqlConnection("server=" + host + ";user id=" + userName + ";password="******";database=" + DataBase + "");
                MySqlCommand    command   = new MySqlCommand();
                MySqlBackup     bk        = new MySqlBackup(command);
                command.Connection = cnnection;
                progressBar1.Value = 0;
                progressBar1.Value = 40;
                cnnection.Open();
                progressBar1.Value = 70;
                bk.ExportToFile(lblfilePath.Text);
                progressBar1.Value = 90;
                cnnection.Close();
                progressBar1.Value = 100;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #21
0
        public void CreateBackup()
        {
            string folder        = DateTime.Now.Date.ToString("yyyy-MM-dd");
            var    root          = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) ?? throw new InvalidOperationException(), "Database backup");
            var    newFolderPath = Path.Combine(root, folder);

            if (!Directory.Exists(newFolderPath))
            {
                Directory.CreateDirectory(newFolderPath);
            }

            string newFileFolderPath = Path.Combine(newFolderPath, $"sqlBackup_time{DateTime.Now:hh-mm-ss}.sql");

            Cursor.Current = Cursors.WaitCursor;
            try
            {
                using (MySqlBackup backup = new MySqlBackup(new MySqlCommand("", _connection)))
                {
                    backup.ExportToFile(newFileFolderPath);
                    MessageBox.Show(@"Backup created.");
                    Cursor.Current = Cursors.Default;
                }
            }
            catch (Exception e)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show(e.ToString());
            }
        }
Exemple #22
0
        //public static String sConex = ConfigurationManager.ConnectionStrings["fiovizabdremoto"].ConnectionString;

        //public static String sConex = ConfigurationManager.ConnectionStrings["connLaptopcarlos"].ConnectionString;
        //public static String sConex = ConfigurationManager.ConnectionStrings["fioviza"].ConnectionString;
        //public static String sConex = ConfigurationManager.ConnectionStrings["fioviza1"].ConnectionString;
        //public static String sConex = ConfigurationManager.ConnectionStrings["connLaptopcarlosfioviza"].ConnectionString;

        //String constring = "server=localhost;user=root;pwd='13101983';database=bdsigefa;Port=3308";

        public void GeneraraBackup(String file)
        {
            try
            {
                //MySqlConnection conn = new MySqlConnection(sConex);
                //MySqlCommand cmd = new MySqlCommand();
                //MySqlBackup mb = new MySqlBackup(cmd);
                //cmd.Connection = conn;
                //conn.Open();
                //mb.ExportToFile(file);
                //conn.Close();
                using (MySqlConnection conn = new MySqlConnection(sConex))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();
                            mb.ExportToFile(file);
                            conn.Close();
                        }
                    }
                }
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemple #23
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("Please select the location of the file first!");
            }
            else
            {
                //code for backing up MySQL database  using open source MySQLBackup library

                string          connectionString = "server=localhost;user=root;pwd=;database=bps;Convert Zero DateTime = true;"; // <- what to backup
                string          filename         = textBox1.Text;
                MySqlConnection conn             = new MySqlConnection(connectionString);
                MySqlCommand    cmd = new MySqlCommand();
                MySqlBackup     mb  = new MySqlBackup(cmd);
                try
                {
                    cmd.Connection = conn;
                    conn.Open();
                    mb.ExportToFile(filename); // <- main backup command
                    MessageBox.Show("Database Backed Up Successfully!!", "Backed Up", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemple #24
0
 /// <summary>
 /// backup tables content when user change the database name from setting
 /// </summary>
 public static void NewDbBackup()
 {
     try
     {
         const string  file = "BackUp\\PHDBNewDBBackup.sql";
         DirectoryInfo dir1 = new DirectoryInfo("BackUp\\");
         using (var conn = DataHolder.MySqlConnection)
         {
             MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 if (!dir1.Exists)
                 {
                     dir1.Create();
                 }
                 if (!File.Exists(file))
                 {
                     FileInfo   f  = new FileInfo(file);
                     FileStream fs = f.Create();
                     fs.Close();
                 }
                 cmd.Connection = conn;
                 conn.Open();
                 mb.ExportInfo.EnableEncryption   = true;
                 mb.ExportInfo.EncryptionPassword = "******";
                 mb.ExportToFile(file);
                 conn.Close();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #25
0
        private void button2_Click(object sender, EventArgs e)
        {
            MySqlConnection conexion = new MySqlConnection();

            conexion.ConnectionString = "server=localhost;port=3306;" +
                                        "dataBase=augustobriga;user=root;pwd=''";

            /*conexion.ConnectionString = "Server=sql7.freemysqlhosting.net;Port=3306;" +
             * "DataBase=sql7261478;user=sql7261478;Pwd=b3xbpjVN6V";*/
            OpenFileDialog dialogo = new OpenFileDialog();

            dialogo.Title            = "Exportar Base de datos medicamentos";
            dialogo.Filter           = "Ficheros SQL | *.sql";
            dialogo.InitialDirectory = @"C:\Users\avanza\Desktop";
            if (dialogo.ShowDialog() == DialogResult.OK)
            {
                using (MySqlConnection conn = new MySqlConnection())
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conexion;
                            conexion.Open();
                            mb.ExportToFile(dialogo.FileName.ToString());
                            conexion.Close();
                        }
                    }
                }
            }
        }
Exemple #26
0
 /// <summary>
 /// backup database the name will be dd-nn-yyyy hh.mm.ss.ms.sql
 /// </summary>
 /// <param name="EnK">Encryption key</param>
 public static void Backup(string EnK)
 {
     try
     {
         string DTime = string.Format("{0}-{1}-{2} {3}.{4}.{5}.{6}", DateTime.Now.Day,
                                      DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour,
                                      DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond);
         string        file = "BackUp\\PHDB " + DTime + ".sql";
         DirectoryInfo dir1 = new DirectoryInfo("BackUp\\");
         using (var conn = DataHolder.MySqlConnection)
         {
             MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 if (!dir1.Exists)
                 {
                     dir1.Create();
                 }
                 cmd.Connection = conn;
                 conn.Open();
                 mb.ExportInfo.EnableEncryption   = true;
                 mb.ExportInfo.EncryptionPassword = EnK;
                 mb.ExportToFile(file);
                 conn.Close();
             }
             MessageBox.Show("تم اخذ نسخه احتياطيه من قاعدة البيانات بنجاح");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #27
0
        public async Task <bool> BackupDatabase(string dumpFile)
        {
            try
            {
                string constring = "server=" + ServerName + ";database=" + DatabaseName + ";user="******";pwd=" + Password + ";convert zero datetime=True";
                using (MySqlConnection conn = new MySqlConnection(constring))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();
                            await Task.Run(() => mb.ExportToFile(dumpFile));

                            conn.Close();
                        }
                    }
                }

                Message = "Success";
                return(true);
            }
            catch (Exception ex)
            {
                Message = Functions.GetErrorFromException(ex);
                return(false);
            }
        }
Exemple #28
0
        private void napraviKopijuToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string         file           = "";
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "MYSQL File (*.sql)|*.sql";
            saveFileDialog.RestoreDirectory = true;

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                file = saveFileDialog.FileName;
            }

            if (file == "")
            {
                return;
            }

            using (MySqlConnection conn = new MySqlConnection(Login.constring))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        mb.ExportToFile(file);
                        conn.Close();
                    }
                }
            }
        }
Exemple #29
0
        public void Backup(string caminhoArquivo, bool resetAutoincremento)
        {
            MySqlCommand cmd = Command();

            try
            {
                MySqlBackup mb = new MySqlBackup(cmd);
                Open();
                mb.ExportInfo.AddCreateDatabase    = true;
                mb.ExportInfo.ExportTableStructure = true;
                mb.ExportInfo.ExportEvents         = true;
                mb.ExportInfo.ExportFunctions      = true;
                mb.ExportInfo.ExportProcedures     = true;
                mb.ExportInfo.ExportTriggers       = true;
                if (resetAutoincremento)
                {
                    mb.ExportInfo.ResetAutoIncrement = true;
                }
                mb.ExportToFile(caminhoArquivo);
                conn.Close();
            }
            catch (MySqlException ex)
            {
                throw new Exception("Erro :" + Environment.NewLine + ex.Message + (ex.InnerException != null ? ex.InnerException.ToString() : String.Empty));
            }
            catch (Exception ex)
            {
                throw new Exception("Erro :" + Environment.NewLine + ex.Message + (ex.InnerException != null ? ex.InnerException.ToString() : String.Empty));
            }
        }
Exemple #30
0
        public ActionResult Index()
        {
            string filePhysicalPath = HttpContext.Server.MapPath("~/backup.sql");

            using (var conn = new MySqlConnection(ConnectionString))
            {
                using (var cmd = new MySqlCommand())
                {
                    using (var mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        mb.ExportToFile(filePhysicalPath);
                    }
                }
            }

            Response.ContentType = "text/plain";
            Response.AppendHeader("Content-Disposition", "attachment; filename=backup" + DateTime.Now + ".sql");
            Response.TransmitFile(filePhysicalPath);
            Response.End();


            return(RedirectToAction("Index"));
        }