private void btExportWithNewHeadersFooters_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();

                            List<string> lstHeaders = new List<string>(txtHeaders.Lines);
                            List<string> lstFooters = new List<string>(txtFooters.Lines);

                            mb.ExportInfo.SetDocumentHeaders(lstHeaders);
                            mb.ExportInfo.SetDocumentFooters(lstFooters);

                            mb.ExportToFile(Program.TargetFile);
                        }
                    }
                }
                MessageBox.Show("Done.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
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());
            }
        }
示例#3
0
 //Backup
 public void Backup()
 {
     try
     {
         string constring = "server=localhost;user=quizuser;pwd=quizpassword;database=quizappmysql;";
         string file = "backup.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 (System.IO.IOException ex)
     {
         System.Windows.Forms.MessageBox.Show("Error , unable to backup!");
     }
 }
示例#4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="caminho"></param>
        /// <returns></returns>
        public bool BackUp(string caminho)
        {
            using (MySqlConnection conn = new MySqlConnection(String.Format(this.conStr, this.HOST, this.USER, this.PASS, this.BASE)))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();

                        try
                        {
                            mb.ExportToFile(caminho);
                            return true;
                        }
                        catch
                        {
                            return false;
                        }
                        finally
                        {
                            conn.Close();
                        }

                    }
                }
            }
        }
示例#5
0
 /// <summary>
 /// Back up a MySql database to the specified file.
 /// </summary>
 public static void Backup(string path, string conectionString)
 {
     using (MySqlConnection conn = new MySqlConnection(conectionString))
     {
         using (MySqlCommand cmd = new MySqlCommand("", conn))
         {
             conn.Open();
             var backup = new MySqlBackup(cmd);
             backup.ExportToFile(path);
             conn.Close();
         }
     }
 }
示例#6
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfBackup = new SaveFileDialog();

            sfBackup.Filter = "sql files (*.sql)|*.sql|All files (*.*)|*.*";
            sfBackup.RestoreDirectory = true;
            //sfBackup.ShowDialog();

            Database dbc = new Database();
            string strconnect = dbc.getString();
            MySqlConnection connect = new MySqlConnection(strconnect);
            connect.Open();
            if (sfBackup.ShowDialog() == DialogResult.OK)
            {
                string filename = "" + sfBackup.FileName + "";

                using (MySqlConnection cn = new MySqlConnection(strconnect))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {

                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = cn;
                            cn.Open();
                            mb.ExportToFile(filename);
                            cn.Close();

                        }

                    }
                }
                try
                {
                    bool backupResult = true;
                    if (backupResult == true)
                    {
                        MessageBox.Show("Sukses Backup Database!", "Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Gagal Backup Database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                catch (SystemException ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void button_Backup_Click(object sender, EventArgs e)
        {
            if (!Program.TargetDirectoryIsValid())
                return;

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

                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            mb.ExportInfo.AddCreateDatabase = cbExAddCreateDatabase.Checked;
                            mb.ExportInfo.ExportTableStructure = cbExAddDropCreateTable.Checked;
                            mb.ExportInfo.ExportRows = cbExExportRows.Checked;
                            mb.ExportInfo.RecordDumpTime = cbExRecordDumpTime.Checked;
                            mb.ExportInfo.ResetAutoIncrement = cbExResetAutoIncrement.Checked;
                            mb.ExportInfo.EnableEncryption = cbExEnableEncryption.Checked;
                            mb.ExportInfo.EncryptionPassword = txtExPassword.Text;
                            mb.ExportInfo.MaxSqlLength = (int)nmExMaxSqlLength.Value;
                            mb.ExportInfo.ExportFunctions = cbExExportRoutines.Checked;
                            mb.ExportInfo.ExportProcedures = cbExExportRoutines.Checked;
                            mb.ExportInfo.ExportTriggers = cbExExportRoutines.Checked;
                            mb.ExportInfo.ExportEvents = cbExExportRoutines.Checked;
                            mb.ExportInfo.ExportViews = cbExExportRoutines.Checked;
                            mb.ExportInfo.ExportRoutinesWithoutDefiner = cbExExportRoutinesWithoutDefiner.Checked;
                            mb.ExportInfo.RowsExportMode = (RowsDataExportMode)comboBox_RowsExportMode.SelectedValue;
                            mb.ExportInfo.WrapWithinTransaction = checkBox_WrapInTransaction.Checked;

                            mb.ExportToFile(Program.TargetFile);
                        }
                        conn.Close();
                    }
                }

                MessageBox.Show("Finished. Dump saved at:" + Environment.NewLine + Environment.NewLine + Program.TargetFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#8
0
 public void ExportData()
 {
     string constring = "server=localhost;user=root;pwd=;database=furniture;";
     string file = "sqlbackup.sql";
     using (con = new MySqlConnection(constring))
     {
         using (command = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(command))
             {
                 command.Connection = con;
                 con.Open();
                 mb.ExportToFile(file);
                 con.Close();
             }
         }
     }
 }
示例#9
0
 public static void exportBackUp(String filename)
 {
     var connection = System.Configuration.ConfigurationManager.ConnectionStrings["admEntities"].ConnectionString;//.Replace("&quot;", "'");
     string constring = connection.Remove(0, connection.IndexOf("server=")).Replace("\"", "");// "server=localhost;user id=root;port=3300;database=adm";// connection;
     string file = 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();
             }
         }
     }
 }
 private void Backup(string sMySQLDatabase, string sFilePath)
 {
     string constring = "server=" + host + ";username="******";password="******";database=" + dbms +
                         ";port=" + port;
     //string file = "C:tempbackup.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(sFilePath);
                 conn.Close();
             }
         }
     }
 }
示例#11
0
        private void Export()
        {
            string constring = ConfigurationManager.ConnectionStrings["ERPContext"].ConnectionString;

            using (MySqlConnection conn = new MySqlConnection(constring))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        mb.ExportToFile(filename);
                        mb.ExportInfo.RecordDumpTime = true;
                        conn.Close();
                    }
                    MessageBox.Show("Backup is successful", "Success", MessageBoxButton.OK);
                }
                isDone = true;
            }
        }
        private void btExport_Click(object sender, EventArgs e)
        {
            if (!Program.TargetDirectoryIsValid())
                return;

            if (checkedListBox1.Items.Count == 0)
            {
                MessageBox.Show("No tables are listed.");
                return;
            }
            try
            {
                List<string> lst = new List<string>();

                foreach (var item in checkedListBox1.CheckedItems)
                {
                    lst.Add(item.ToString());
                }

                using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();
                            mb.ExportInfo.ExcludeTables = lst;
                            mb.ExportToFile(Program.TargetFile);
                        }
                    }
                }
                MessageBox.Show("Done.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public static void exportDataBase()
        {
            try
            {
                // On demande l'endroit de la sauvegarde à l'utilisateur
                FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();

                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        // On affecte le chemin de l'utilisateur et on utilise le fichier pour la sauvegarde
                        string fileexport = folderBrowserDialog1.SelectedPath + "\\backup_gestionstock.sql";

                        // On définit les variables
                        MySqlCommand cmd = new MySqlCommand();
                        MySqlBackup mb = new MySqlBackup(cmd);

                        // On ouvre la connexion, utilise la fonction du package et on ferme la connexion
                        cmd.Connection = M_connexion.Gestion;
                        M_connexion.Gestion.Open();

                        mb.ExportToFile(fileexport);
                        M_connexion.Gestion.Close();
                        MessageBox.Show("Base de données sauvegardée." + Environment.NewLine + "Le fichier se trouve dans le chemin : " + fileexport);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Erreur: " + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur: " + ex.Message);
            }
        }
示例#14
0
 private void backUpToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         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();
                 }
             }
         }
         MessageBox.Show("BACKUP SUCCESS");
     }
     catch (Exception fe)
     {
         MessageBox.Show(fe.ToString());
     }
 }
示例#15
0
        protected void btnExportSql_Click(object sender, EventArgs e)
        {
            string constring = ConfigurationManager.ConnectionStrings["clonedeploy"].ConnectionString;
            string exportPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "private" +
                         Path.DirectorySeparatorChar + "exports" + Path.DirectorySeparatorChar;

            using (MySqlConnection conn = new MySqlConnection(constring))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        mb.ExportToFile(exportPath + "dbDump.sql");
                        conn.Close();
                    }
                }
            }

            EndUserMessage = "Export Complete";


        }
示例#16
0
 public static bool BackUp(string file_name)
 {
     try
     {
         if (!connect()) return false;
         using (MySqlBackup mb = new MySqlBackup(cmd))
         {
             mb.ExportInfo.AddCreateDatabase = true;
             mb.ExportInfo.ExportTableStructure = true;
             mb.ExportInfo.ExportRows = true;
             mb.ExportToFile(file_name);
             return true;
         }
     }
     catch (Exception ex)
     {
         ErrorHandler.Errors.displayError("We were unable to back up the database.", ErrorHandler.ErrorCode.BackUpDB, ErrorHandler.ErrorAction.Exit, ex);
         return false;
     }
 }
示例#17
0
        private static bool MysqlCreateDump()
        {
            Console.WriteLine("Creating  dump...");
            using (
                MySqlConnection conn =
                    new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultContext"].ConnectionString))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        try
                        {
                            conn.Open();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Can't connect to MySQL server");
                            Console.WriteLine("Details :{0}", e.Message);
                            return false;
                        }

                        mb.ExportInfo.AddCreateDatabase = false;
                        mb.ExportInfo.ExportTableStructure = true;
                        mb.ExportInfo.ExportRows = false;
                        try
                        {
                            mb.ExportToFile(_fileNameSql);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Can't create struct dump");
                            Console.WriteLine("Details :{0}", e.Message);
                            return false;
                        }
                    }
                }

            }

            using (
                MySqlConnection conn =
                    new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultContext"].ConnectionString))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        try
                        {
                            conn.Open();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Can't connect to MySQL server");
                            Console.WriteLine("Details :{0}", e.Message);
                            return false;
                        }

                        mb.ExportInfo.AddCreateDatabase = false;
                        mb.ExportInfo.ExportTableStructure = false;
                        mb.ExportInfo.ExportRows = true;
                        try
                        {
                            mb.ExportToFile(_fileNameData);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Can't create dump");
                            Console.WriteLine("Details :{0}", e.Message);
                            return false;
                        }
                    }
                }
            }
            return true;
        }
示例#18
0
 //MySql backup !!!!!!
 public void MySQLExport(bool sve, List<string> tablice, bool pogledi, bool procedure, bool okidaci, string ConnectionString, string pohrana)
 {
     using (MySqlConnection con = new MySqlConnection(ConnectionString))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 cmd.Connection = con;
                 con.Open();
                 if (sve == true)
                 {
                     mb.ExportInfo.AddCreateDatabase = true; //mje
                     mb.ExportInfo.ExportTableStructure = true;
                     mb.ExportInfo.ExportRows = true;
                     mb.ExportInfo.ExportEvents = true;
                     mb.ExportInfo.ExportFunctions = true;
                     mb.ExportInfo.ExportProcedures = true;
                     mb.ExportInfo.ExportTriggers = true;
                     mb.ExportInfo.ExportViews = true;
                     mb.ExportToFile(pohrana);
                 }
                 else if (tablice.Count > 0)
                 {
                     mb.ExportInfo.AddCreateDatabase = false; //mje
                     mb.ExportInfo.ExportTableStructure = true;
                     mb.ExportInfo.TablesToBeExportedList = tablice;
                     mb.ExportInfo.ExportRows = true;
                     mb.ExportInfo.ExportEvents = false;
                     mb.ExportInfo.ExportFunctions = false;
                     mb.ExportInfo.ExportProcedures = false;
                     mb.ExportInfo.ExportTriggers = false;
                     mb.ExportInfo.ExportViews = false;
                     mb.ExportToFile(pohrana);
                 }
                 else if (okidaci == true)
                 {
                     mb.ExportInfo.AddCreateDatabase = false;
                     mb.ExportInfo.ExportTableStructure = false;
                     mb.ExportInfo.ExportRows = false;
                     mb.ExportInfo.ExportEvents = false;
                     mb.ExportInfo.ExportFunctions = false;
                     mb.ExportInfo.ExportProcedures = false;
                     mb.ExportInfo.ExportTriggers = true;
                     mb.ExportInfo.ExportViews = false;
                     mb.ExportToFile(pohrana);
                 }
                 else if (procedure == true)
                 {
                     mb.ExportInfo.AddCreateDatabase = false;
                     mb.ExportInfo.ExportTableStructure = false;
                     mb.ExportInfo.ExportRows = false;
                     mb.ExportInfo.ExportEvents = false;
                     mb.ExportInfo.ExportFunctions = false;
                     mb.ExportInfo.ExportProcedures = true;
                     mb.ExportInfo.ExportTriggers = false;
                     mb.ExportInfo.ExportViews = false;
                     mb.ExportToFile(pohrana);
                 }
                 else if (pogledi == true)
                 {
                     mb.ExportInfo.AddCreateDatabase = false;
                     mb.ExportInfo.ExportTableStructure = false;
                     mb.ExportInfo.ExportRows = false;
                     mb.ExportInfo.ExportEvents = false;
                     mb.ExportInfo.ExportFunctions = false;
                     mb.ExportInfo.ExportProcedures = false;
                     mb.ExportInfo.ExportTriggers = false;
                     mb.ExportInfo.ExportViews = true;
                     mb.ExportToFile(pohrana);
                     string zamjena = File.ReadAllText(pohrana);
                     zamjena = zamjena.Replace("DROP", "#DROP");
                     File.WriteAllText(pohrana, zamjena);
                 }
             }
         }
         con.Close();
     }
 }
        private void btExportDic_Click(object sender, EventArgs e)
        {
            if (!Program.TargetDirectoryIsValid())
                return;

            Dictionary<string, string> dic = new Dictionary<string, string>();

            foreach (DataGridViewRow r in dataGridView1.Rows)
            {
                if (Convert.ToBoolean(r.Cells[colnSelect.Index].Value))
                {
                    string tableName = r.Cells[colnTable.Index].Value + "";
                    string sql = r.Cells[colnSql.Index].Value + "";

                    dic[tableName] = sql;
                }
            }

            if (dic.Count == 0)
                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.ExportInfo.TablesToBeExportedDic = dic;
                            mb.ExportToFile(Program.TargetFile);

                            conn.Close();
                        }
                    }
                }

                MessageBox.Show("Done.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#20
0
        public static DateTime BackupSystemTables()
        {
            string time = DateTime.Now.ToString();
            time=time.Replace('/', '_');
            time = time.Replace(':', '-');
            var file = BackUpFilePath+"\\" + time;

            using (var cmd = new MySqlCommand())
            {
                using (var mb = new MySqlBackup(cmd))
                {
                    cmd.Connection = _connectionSystem;
                    mb.ExportToFile(file);
                }
            }
            time = time.Replace('_', '/');
            time = time.Replace('-', ':');
            return Convert.ToDateTime(time);
        }
示例#21
0
        private void btExportFileZip_Click(object sender, EventArgs e)
        {
            try
            {
                FolderBrowserDialog f = new FolderBrowserDialog();
                f.Description = "Select a folder to save the dump file and zip file.";
                if (f.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                string timenow = DateTime.Now.ToString("yyyyMMddHHmmss");
                string folder = f.SelectedPath;
                string filename = "dump" + timenow + ".sql";
                string fileDump = f.SelectedPath + "\\" + filename;
                string fileZip = f.SelectedPath + "\\dumpzip" + timenow + ".zip";

                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(fileDump);

                            conn.Close();
                        }
                    }
                }

                using (ZipStorer zip = ZipStorer.Create(fileZip, "MySQL Dump"))
                {
                    zip.AddFile(ZipStorer.Compression.Deflate, fileDump, filename, "MySQL Dump");
                }

                MessageBox.Show("Finished.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#22
0
        public static void Backup(string dir, bool genSQL)
        {
            using (MySqlConnection connect = new MySqlConnection(AppProperties.ConnectionString()))
            {
                using (MySqlCommand command = new MySqlCommand())
                {
                    command.Connection = connect;
                    using (MySqlBackup backup = new MySqlBackup(command))
                    {
                        string backDir = dir.Replace("cbf", "sql"); //backDir is .sql

                        try
                        {
                            if (genSQL)
                            {
                                connect.Open();
                                backup.ExportInfo.ExportTableStructure = true;
                                backup.ExportToFile(backDir);
                                backup.ExportInfo.EnableEncryption = true;
                                backup.ExportInfo.EncryptionPassword = "******";
                                backup.ExportToFile(dir);
                            }
                            else
                            {
                                connect.Open();
                                backup.ExportInfo.ExportTableStructure = true;
                                backup.ExportInfo.EnableEncryption = true;
                                backup.ExportInfo.EncryptionPassword = "******";
                                backup.ExportToFile(dir);
                            }
                        }
                        catch (Exception ex)
                        {
                            XtraMessageBox.Show(ex.Message, "An error has occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }
        bool ExecuteBackup()
        {
            logger.Info ("Создаем резервную копию базы.");
            if(String.IsNullOrWhiteSpace (entryFileName.Text))
            {
                logger.Warn ("Имя файла резервной копии пустое. Отмена.");
                return true;
            }

            progressbarTotal.Text = "Создание резервной копии";
            progressbarOperation.Visible = true;
            QSMain.WaitRedraw ();

            using (MySqlCommand cmd = QSMain.connectionDB.CreateCommand ())
            {
                using (MySqlBackup mb = new MySqlBackup(cmd))
                {
                    var dir = System.IO.Path.GetDirectoryName (entryFileName.Text);

                    if (!Directory.Exists (dir))
                        Directory.CreateDirectory (dir);

                    logger.Debug (entryFileName.Text);
                    mb.ExportProgressChanged += Mb_ExportProgressChanged;
                    mb.ExportToFile(entryFileName.Text);
                }
            }

            progressbarOperation.Visible = false;
            return false;
        }
示例#24
0
 private void DoBackup(object sender,DoWorkEventArgs e)
 {
     attempts++;
     new Log("Back-up operation for \""+alias+"\" started.");
     RaiseDoingBackup();
     using (connection)
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 try
                 {
                     cmd.Connection = connection;
                     connection.Open();
                     mb.ExportToFile(file);
                     connection.Close();
                     new Log("Back-up operation for \"" + alias + "\" completed successfully.");
                     emailSettings.NotifyCheck(alias,EmailNotifications.BACKUP_OPERATION_OK);
                     cryptographySettings.SetFile(file);
                     cryptographySettings.SetMode(Cryptography.ENCRYPT);
                     cryptographySettings.DoCryptography();
                     DeleteOldFiles();
                     ftpSettings.Transmission(this,emailSettings);
                     DeleteAfterBackup();
                     ftpSettings.DeleteOld(this);
                 }
                 catch (Exception ex)
                 {
                     if (attempts < 6)
                         DoBackup(sender,e);
                     else
                     {
                         new Log("ERROR: Back-up operation for \"" + alias + "\" failed.");
                         emailSettings.NotifyCheck(alias, EmailNotifications.BACKUP_OPERATION_FAIL);
                     }
                 }
             }
         }
     }
     RaiseFinished();
 }
        public static void exporter()
        {
            string file = "C:\\Users\\Rodaxfck\\Desktop";

            using (MySqlCommand cmd = new MySqlCommand())
            {
                using (MySqlBackup mb = new MySqlBackup(cmd))
                {
                    cmd.Connection = M_connexion.Gestion;
                    M_connexion.Gestion.Open();
                    mb.ExportToFile(file);
                    M_connexion.Gestion.Close();
                }
            }

        }
        //Export database
        private void exportDB_Btn_Click(object sender, EventArgs e)
        {
            String database = null;
            String connStr = null;
            MySqlConnection connection = null;
            MySqlCommand cmd = null;
            try
            {
                database = listBox1.SelectedItem.ToString();
                connStr = "Server=localhost; Port=3306; Database=" + database + "; Uid=root; Pwd=admin;";
                connection = new MySqlConnection(connStr);
                cmd = new MySqlCommand();
                MySqlBackup backup = new MySqlBackup(cmd);
                cmd.Connection = connection;
                connection.Open();

                //Select the folder you want to save it in
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                DialogResult result = fbd.ShowDialog();
                String file = fbd.SelectedPath + "\\" + database + "_backup.sql";

                backup.ExportInfo.AddCreateDatabase = true;
                backup.ExportInfo.ExportTableStructure = true;
                backup.ExportInfo.ExportRows = true;
                backup.ExportToFile(file);
                MessageBox.Show("Backup has been exported");

            }
            catch (Exception)
            {
                if (database == null)
                {
                    MessageBox.Show("Please select a database to export");
                }
            }
            finally
            {
                if (connection == null)
                {
                    //Do nothing !
                }
                else if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
        }
示例#27
0
 public static bool BackUp(string dir, int max_backups)
 {
     try
     {
         if (!connect()) return false;
         string file = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString().Replace(':', '.');
         if (!Directory.Exists(dir))
         {
             Directory.CreateDirectory(dir);
         }
         else
         {
             DirectoryInfo directory = new DirectoryInfo(dir);
             FileInfo[] back_up_files = directory.GetFiles("*.sql").OrderByDescending(f => f.LastWriteTime).ToArray();
             if (back_up_files.Length >= max_backups)
             {
                 back_up_files.Last().Delete();
             }
         }
         using (MySqlBackup mb = new MySqlBackup(cmd))
         {
             mb.ExportInfo.AddCreateDatabase = true;
             mb.ExportInfo.ExportTableStructure = true;
             mb.ExportInfo.ExportRows = true;
             mb.ExportToFile(dir + @"\" + file + ".sql");
             return true;
         }
     }
     catch (Exception ex)
     {
         ErrorHandler.Errors.displayError("We were unable to back up the database.", ErrorHandler.ErrorCode.BackUpDB, ErrorHandler.ErrorAction.Exit, ex);
         return false;
     }
 }
示例#28
0
 public void ImportData()
 {
     string constring = "server=localhost;user=root;pwd=qwerty;database=test;";
     string file = "C:\\backup.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();
             }
         }
     }
 }