예제 #1
0
        private void btImportUnzipMemoryStream_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog f = new OpenFileDialog();
                f.Filter = "Zip|*.zip";
                if (f.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                string file = f.FileName;

                using (MemoryStream ms = new MemoryStream())
                {
                    using (ZipStorer zip = ZipStorer.Open(file, FileAccess.Read))
                    {
                        List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
                        zip.ExtractFile(dir[0], ms);

                        ms.Position = 0;
                        using (TextReader tr = new StreamReader(ms))
                        {
                            using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
                            {
                                using (MySqlCommand cmd = new MySqlCommand())
                                {
                                    using (MySqlBackup mb = new MySqlBackup(cmd))
                                    {
                                        cmd.Connection = conn;
                                        conn.Open();

                                        mb.ImportFromTextReader(tr);

                                        conn.Close();
                                    }
                                }
                            }
                        }
                    }
                }
                MessageBox.Show("Finished.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            Stream         myS             = null;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter           = "BackUp File (*.sql)|*.sql";
            saveFileDialog1.RestoreDirectory = true;
            try
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if ((myS = saveFileDialog1.OpenFile()) != null)
                    {
                        SQLConn.ConnDB();
                        SQLConn.cmd = new MySqlCommand(SQLConn.sqL, SQLConn.conn);
                        MySqlBackup mb   = new MySqlBackup(SQLConn.cmd);
                        string      file = Path.GetFullPath(saveFileDialog1.FileName);
                        myS.Close();


                        mb.ExportInfo.AddCreateDatabase = true;
                        List <string> abc = new List <string>();

                        abc.Add("daccounts");
                        abc.Add("saccounts");
                        abc.Add("debtin");
                        abc.Add("debtins");
                        abc.Add("payment");
                        abc.Add("transactions");
                        abc.Add("transactiondetails");
                        abc.Add("stockin");
                        abc.Add("staff");
                        abc.Add("product");
                        abc.Add("category");

                        mb.ExportInfo.TablesToBeExportedList = abc;
                        mb.ExportInfo.ExportTableStructure   = true;
                        mb.ExportInfo.ExportRows             = true;
                        mb.ExportToFile(file);
                        MessageBox.Show("BackUp Successfully Completed.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("BackUp UnSuccessfull. " + ex);
            }
        }
예제 #3
0
 private void button21_Click(object sender, EventArgs e)
 {
     using (MySqlConnection conn = new MySqlConnection(Var.Sqlmy))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 cmd.Connection = conn;
                 conn.Open();
                 mb.ExportToFile(Var.ini.backup);
                 conn.Close();
             }
         }
     }
 }
예제 #4
0
 public void RestoreDB(string connstring, string fileTarget)
 {
     using (MySqlConnection conn = new MySqlConnection(connstring))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 cmd.Connection = conn;
                 conn.Open();
                 mb.ImportFromFile(fileTarget);
                 conn.Close();
             }
         }
     }
 }
예제 #5
0
 public void CreateBackup(string connstring, string fileTarget)
 {
     using (MySqlConnection conn = new MySqlConnection(connstring))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 cmd.Connection = conn;
                 conn.Open();
                 mb.ExportToFile(fileTarget);
                 conn.Close();
             }
         }
     }
 }
 public void RestoreDatabase(string fileLocation)
 {
     try
     {
         using (var context = new DbContext())
         {
             var mysqlBackup = new MySqlBackup();
             mysqlBackup.Command = (MySqlCommand)context.Conn.CreateCommand();
             mysqlBackup.ImportFromFile(fileLocation);
         }
     }
     catch (MySqlException ex)
     {
         throw ex;
     }
 }
예제 #7
0
 public static void BackupDb(string connectionString, string outputFile)
 {
     using (MySqlConnection conn = new MySqlConnection(connectionString))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 cmd.Connection = conn;
                 conn.Open();
                 mb.ExportToFile(outputFile);
                 conn.Close();
             }
         }
     }
 }
예제 #8
0
 private void BackupMysqlToSqlFile(string connectionString, string dataBaseDir)
 {
     using (MySqlConnection conn = new MySqlConnection(connectionString))
     {
         string fileName = conn.Database + ".sql";
         if (conn.State != ConnectionState.Open)
         {
             conn.Open();
         }
         MySqlCommand cmd = new MySqlCommand();
         MySqlBackup  mb  = new MySqlBackup(cmd);
         cmd.Connection = conn;
         mb.ExportToFile(dataBaseDir + "\\" + fileName);
         conn.Close();
     }
 }
예제 #9
0
 internal static void Restore(string database, string backupFile)
 {
     using (var conn = new MySqlConnection(ConnectionString(database)))
     {
         using (var cmd = new MySqlCommand())
         {
             using (var mb = new MySqlBackup(cmd))
             {
                 cmd.Connection = conn;
                 conn.Open();
                 mb.ImportFromFile(backupFile);
                 conn.Close();
             }
         }
     }
 }
        public FormTestImportProgressReport()
        {
            InitializeComponent();

            mb = new MySqlBackup();
            mb.ImportInfo.IntervalForProgressReport = (int)nmImInterval.Value;
            mb.ImportProgressChanged += mb_ImportProgressChanged;

            timer1          = new Timer();
            timer1.Interval = 50;
            timer1.Tick    += timer1_Tick;

            bwImport                     = new BackgroundWorker();
            bwImport.DoWork             += bwImport_DoWork;
            bwImport.RunWorkerCompleted += bwImport_RunWorkerCompleted;
        }
예제 #11
0
        //BACKUP EPICOR EAGLE (TO FILE)(*.SQL)
        public static void BackupMySqlDatabaseByTable()
        {
            //get connection string
            string myConnectionString = EpicorEagleConnect.GetSqlConnectionString();

            //string constring = "server=localhost;user=root;pwd=qwerty;database=test;";
            //string myConnectionString = "SERVER=10.0.1.7; " +
            //    "DATABASE=EAGLEDW; " +
            //    "UID=dbread; " +
            //    "PASSWORD=havemox1e;";
            //string myConnectionString = "SERVER=localhost; " +
            //    "DATABASE=travelexperts; " +
            //    "UID=root; " +
            //    "PASSWORD=;";

            try
            {
                string file = @"C:\_000_BACKUP\EpicorEagleDb.sql";
                using (MySqlConnection conn = new MySqlConnection(myConnectionString))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();

                            //List<string> myTableList = new List<string> { "customers", "agents" };
                            List <string> myTableList = new List <string> {
                                "ADR", "ADRV"
                            };
                            mb.ExportInfo.TablesToBeExportedList = myTableList;
                            mb.ExportToFile(file);
                            conn.Close();
                        }
                    }
                }
            }
            catch (MySqlException ex1)
            {
                Console.WriteLine("Message: " + ex1.Message + "\nStack: " + ex1.StackTrace);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Message: " + ex.Message + "\nStack: " + ex.StackTrace);
            }
        }
예제 #12
0
        public bool TakeBackup(string application)
        {
            string connectionString = ConfigurationManager.AppSettings["connectionString"];
            string fileLocation     = ConfigurationManager.AppSettings["backUpLocation"];
            string folderName       = DateTime.Today.FormatDate("-");
            string pathString       = System.IO.Path.Combine(fileLocation, application, folderName);
            string fileName         = DateTime.Now.ToString("dd-MMM-yyyy hh-mm-ss") + ".sql";
            bool   doesFolderExist  = System.IO.Directory.Exists(pathString);

            if (!doesFolderExist)
            {
                System.IO.Directory.CreateDirectory(pathString);
            }

            string          filePath = System.IO.Path.Combine(pathString, fileName);
            MySqlCommand    command;
            MySqlConnection connection = null;
            MySqlBackup     backup;

            try
            {
                using (connection = new MySqlConnection(connectionString))
                {
                    using (command = new MySqlCommand())
                    {
                        using (backup = new MySqlBackup(command))
                        {
                            command.Connection = connection;
                            connection.Open();
                            backup.ExportToFile(filePath);
                            connection.Close();
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                if (connection != null)
                {
                    connection.Close();
                }
                logger.Log(exception);
                return(false);
            }

            return(true);
        }
예제 #13
0
        private static int ImportCharacters(CommandLineOptions.ImportOptions opts)
        {
            var importFileName = System.Configuration.ConfigurationManager.AppSettings["DefaultOutputFile"];

            if (!String.IsNullOrEmpty(opts.ImportFileName))
            {
                importFileName = opts.ImportFileName;
            }

            Logger.Debug($"Command Line Options : {importFileName}");

            var connection = new MySqlConnection(ConnectionString);

            try
            {
                Logger.Info($"Connecting to {ConnectionString}. Exporting to {importFileName}");
                Logger.Info("Start Character Import");


                using (MySqlConnection conn = new MySqlConnection(ConnectionString))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();
                            mb.ImportFromFile(importFileName);
                            conn.Close();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Logger.Error($"Exception : {e.Message}");
                throw;
            }
            finally
            {
                connection.Close();
                Logger.Info("Done Character Export");
            }

            return(0);
        }
        //Import database
        private void importDB_Btn_Click(object sender, EventArgs e)
        {
            String         database = null;
            OpenFileDialog ofd      = new OpenFileDialog();

            ofd.Title  = "Select directory to import SQL";
            ofd.Filter = "SQL Files (.sql)|*.sql";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                database = ofd.FileName;
            }

            String          connStr    = "Server=localhost; Port=3306; Uid=root; Pwd=admin;";
            MySqlConnection connection = new MySqlConnection(connStr);

            try
            {
                MySqlCommand cmd    = new MySqlCommand();
                MySqlBackup  backup = new MySqlBackup(cmd);
                cmd.Connection = connection;
                connection.Open();
                backup.ImportInfo.TargetDatabase         = splitDir(database);
                backup.ImportInfo.DatabaseDefaultCharSet = "utf8";
                backup.ImportFromFile(database);
                MessageBox.Show("Backup has been imported");
            }
            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();
                    listBox1.Items.Clear();
                    showDBList();
                }
            }
        }
        //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();
                }
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
            if (richTextBox1.Text.Length == 0)
            {
                errorProvider1.SetError(richTextBox1, "This field must be filled up");

                label16.ForeColor = Color.Red;
                MessageBox.Show("A field must be required!");
                //MessageBox.Show("Must choose a location to save backup", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string file = richTextBox1.Text;
                using (MySqlConnection conn = ConString.Connection)
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            try
                            {
                                DialogResult diaRes = MessageBox.Show("Are you sure you want to create backup?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (diaRes == DialogResult.Yes)
                                {
                                    //DialogResult diaRes = MessageBox.Show("Are you sure you want to create backup?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                                    cmd.Connection = conn;

                                    mb.ExportToFile(file);
                                    conn.Close();

                                    //s.Speak("Backup Success!");
                                    MessageBox.Show("Backup Created Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else if (diaRes == DialogResult.No)
                                {
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
                    }
                }
            }
        }
예제 #17
0
        /// <summary>
        /// 还原数据库
        /// </summary>
        /// <param name="strPath">指定还原文件***.sql的绝对路径</param>
        /// <param name="dbName">还原到指定数据库</param>
        /// <returns></returns>
        public static bool RestoreDB(string strPath, string dbName)
        {
            bool isImport = false;

            try
            {
                MySqlConnection myconn = new MySqlConnection(ConnectString);
                if (myconn.State == ConnectionState.Closed)
                {
                    myconn.Open();
                }
                try
                {
                    if (string.IsNullOrEmpty(strPath))
                    {
                        return(isImport);
                    }
                    using (MySqlCommand cmmd = new MySqlCommand())
                    {
                        using (MySqlBackup backCmd = new MySqlBackup(cmmd))
                        {
                            cmmd.Connection     = myconn;
                            cmmd.CommandTimeout = 3600;
                            backCmd.ImportInfo.TargetDatabase         = dbName;//前提条件 当前 myconn 中的用户有建库等系列权限
                            backCmd.ImportInfo.DatabaseDefaultCharSet = "utf8";
                            backCmd.ImportFromFile(strPath);
                            isImport = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    if (myconn.State == ConnectionState.Open)
                    {
                        myconn.Close();
                        myconn.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(isImport);
        }
예제 #18
0
        void DoRestore()
        {
            string[] files = Directory.GetFiles(folder);

            DateTime timeProcessStart = DateTime.Now;

            using (MySqlConnection conn = new MySqlConnection(constr))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    conn.Open();
                    cmd.Connection = conn;

                    foreach (string file in files)
                    {
                        string db = Path.GetFileNameWithoutExtension(file);

                        DateTime dateStart = DateTime.Now;

                        string appendText = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "  Restore " + db + "....";
                        bw.ReportProgress(0, appendText);

                        cmd.CommandText = "create database if not exists `" + db + "`";
                        cmd.ExecuteNonQuery();

                        cmd.CommandText = $"use `{db}`";
                        cmd.ExecuteNonQuery();

                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            mb.ImportFromFile(file);
                        }

                        DateTime dateEnd = DateTime.Now;

                        var timeElapsed = dateEnd - dateStart;

                        appendText = $" completed ({timeElapsed.Hours} h {timeElapsed.Minutes} m {timeElapsed.Seconds} s {timeElapsed.Milliseconds} ms)\r\n";
                        bw.ReportProgress(0, appendText);

                        count++;
                    }

                    conn.Close();
                }
            }
        }
예제 #19
0
 private void Backup_Button_Click(object sender, EventArgs e)
 {
     using (mysqlConnection = new MySqlConnection(connection))
     {
         using (myCommand = new MySqlCommand())
         {
             using (mybackup = new MySqlBackup(myCommand))
             {
                 myCommand.Connection = mysqlConnection;
                 mysqlConnection.Open();
                 mybackup.ExportToFile(Location_Text.Text + "\\resturant.sql");
                 MessageBox.Show("Database Backup successfully");
                 mysqlConnection.Close();
             }
         }
     }
 }
예제 #20
0
        private static string GetDatabaseSqlDump(string planName, string connectionString)
        {
            var sql = string.Empty;

            using (var connection = new MySqlConnection(connectionString)) {
                using (var command = new MySqlCommand()) {
                    using (var backup = new MySqlBackup(command)) {
                        command.Connection = connection;
                        connection.Open();
                        sql = backup.ExportToString();
                        connection.Close();
                    }
                }
            }

            return(sql);
        }
예제 #21
0
        /// <summary>
        /// 还原数据库
        /// </summary>
        /// <param name="path">指定还原文件***.sql的绝对路径</param>
        /// <param name="dbName">还原到指定数据库</param>
        /// <returns></returns>
        public static bool RestoreDb(string path, string dbName)
        {
            bool isSuccess = false;

            try
            {
                MutiDBOperate mutiDB = Appsettings.app <MutiDBOperate>("DBS")
                                       .Where(i => i.Enabled && i.ConnId == "WMBLOG_MYSQL").First();
                MySqlConnection myconn = new MySqlConnection(mutiDB.Connection);
                if (myconn.State == ConnectionState.Closed)
                {
                    myconn.Open();
                }
                try
                {
                    using (MySqlCommand cmmd = new MySqlCommand())
                    {
                        using (MySqlBackup backCmd = new MySqlBackup(cmmd))
                        {
                            cmmd.Connection     = myconn;
                            cmmd.CommandTimeout = 3600;
                            //backCmd.ImportInfo.TargetDatabase = dbName;//前提条件 当前 myconn 中的用户有建库等系列权限
                            //backCmd.ImportInfo.DatabaseDefaultCharSet = "utf8";
                            backCmd.ImportFromFile(path);
                            isSuccess = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Console.WriteLine($"BackupDB_备份数据库异常 sql:{cmdText}. {ex.Message}", "MYSQLIMPL");
                }
                finally
                {
                    if (myconn.State == ConnectionState.Open)
                    {
                        myconn.Close();
                        myconn.Dispose();
                    }
                }
            }
            catch (Exception)
            {
            }
            return(isSuccess);
        }
        private void btGetHeadersFooters_Click(object sender, EventArgs e)
        {
            using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();

                        txtHeaders.Lines = mb.ExportInfo.GetDocumentHeaders(cmd).ToArray();
                        txtFooters.Lines = mb.ExportInfo.GetDocumentFooters().ToArray();
                    }
                }
            }
        }
예제 #23
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (Program.ISSaDmin)
            {
                constr = Program.Str_con;
                LoadTables();
                SaveFileDialog sf = new SaveFileDialog();
                sf.FileName = "commerce_" + DateTime.Now.ToString("yyyy_MM_dd_HHmmss") + ".sql";
                if (sf.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                mb = new MySqlBackup(constr);
                mb.ExportInfo.EncryptionKey                  = "Harrazi";
                mb.ExportInfo.EnableEncryption               = true;
                mb.ExportInfo.FileName                       = sf.FileName;
                mb.ExportInfo.MaxSqlLength                   = 1024;
                mb.ExportInfo.ExportRows                     = true;
                mb.ExportInfo.ExportTableStructure           = true;
                mb.ExportInfo.ExportViews                    = true;
                mb.ExportInfo.ExportTriggers                 = true;
                mb.ExportInfo.ExportEvents                   = true;
                mb.ExportInfo.ExportFunctions                = true;
                mb.ExportInfo.AsynchronousMode               = true;
                mb.ExportInfo.CalculateTotalRowsFromDatabase = true;
                mb.ExportInfo.AutoCloseConnection            = true;
                mb.ExportInfo.RecordDumpTime                 = true;
                mb.ExportInfo.TableCustomSql                 = GetTableSql();


                TimerExport          = new Timer();
                TimerExport.Interval = 10;
                TimerExport.Tick    += new EventHandler(TimerExport_Tick);
                TimerExport.Start();
                mb.ExportProgressChanged += new MySqlBackup.exportProgressChange(mb_ExportProgressChanged);
                mb.Export();


                buttonX1.Visible = false;
            }
            else
            {
                MessageBox.Show("Accés Non Autorisé");
            }
        }
예제 #24
0
 public static void Yedekle(string path)
 {
     using (MySqlConnection _connection = new MySqlConnection(DatabaseInf.Veritabani))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             using (MySqlBackup backup = new MySqlBackup(cmd))
             {
                 cmd.Connection = _connection;
                 _connection.Open();
                 backup.ExportToFile(path);
                 _connection.Close();
                 MessageBox.Show("Başarıyla kaydedildi.");
             }
         }
     }
 }
예제 #25
0
        /// <summary>
        /// 备份数据库
        /// </summary>
        /// <param name="cmdText">指定准备备份的文件名 以***.sql为标准</param>
        /// <returns></returns>
        public static bool BackupDB(string cmdText)
        {
            bool isBack = false;

            try
            {
                MySqlConnection myconn = new MySqlConnection(ConnectString);
                if (myconn.State == ConnectionState.Closed)
                {
                    myconn.Open();
                }
                try
                {
                    if (string.IsNullOrEmpty(cmdText))
                    {
                        return(isBack);
                    }
                    using (MySqlCommand cmmd = new MySqlCommand())
                    {
                        using (MySqlBackup backCmd = new MySqlBackup(cmmd))
                        {
                            cmmd.Connection                 = myconn;
                            cmmd.CommandTimeout             = 60;
                            backCmd.ExportInfo.MaxSqlLength = 1024;//指定备份文件的大小
                            backCmd.ExportToFile(cmdText);
                            isBack = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    if (myconn.State == ConnectionState.Open)
                    {
                        myconn.Close();
                        myconn.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(isBack);
        }
예제 #26
0
        private static void BackupSelectedDatabase(string databaseName)
        {
            using (MySqlConnection connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = connection;
                        connection.Open();
                        connection.ChangeDatabase(databaseName);

                        mb.ExportToFile(string.Format(BackupFileName, connection.Database));
                    }
                }
            }
        }
예제 #27
0
 public static void GeriYukle(string path)
 {
     using (MySqlConnection conn = new MySqlConnection(DatabaseInf.Veritabani))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 cmd.Connection = conn;
                 conn.Open();
                 mb.ImportFromFile(path);
                 conn.Close();
                 MessageBox.Show("Başarıyla yüklendi.");
             }
         }
     }
 }
예제 #28
0
 private void Restore_Button_Click(object sender, EventArgs e)
 {
     using (mysqlConnection = new MySqlConnection(connection))
     {
         using (myCommand = new MySqlCommand())
         {
             using (mybackup = new MySqlBackup(myCommand))
             {
                 myCommand.Connection = mysqlConnection;
                 mysqlConnection.Open();
                 mybackup.ImportFromFile(Restore_Text.Text);
                 MessageBox.Show("Database Restore Successfully");
                 mysqlConnection.Close();
             }
         }
     }
 }
예제 #29
0
        public bool ExportarBaseDatos(string ruta, string nombreArchivo)
        {
            MySqlConnection conexion;

            conexion = Sql.ObtenerConexion();

            if (String.IsNullOrWhiteSpace(nombreArchivo))
            {
                nombreArchivo = "backup " + DateTime.Now.ToString("dd-mm-ss MM-yyyy") + ".sql";
            }
            else
            {
                nombreArchivo += DateTime.Now.ToString("dd-mm-ss MM-yyyy") + ".sql";
            }

            if (String.IsNullOrWhiteSpace(ruta))
            {
                ruta = Application.ExecutablePath;
            }
            else
            {
                ruta += "\\";
            }

            using (MySqlCommand cmd = new MySqlCommand())
            {
                using (MySqlBackup backup = new MySqlBackup(cmd))
                {
                    backup.ExportInfo.AddCreateDatabase         = true;
                    backup.ExportInfo.IntervalForProgressReport = 50;
                    backup.ExportInfo.GetTotalRowsBeforeExport  = true;
                    backup.ExportProgressChanged += backup_ExportProgressChanged;
                    cmd.Connection = conexion;
                    try
                    {
                        conexion.Open();
                        backup.ExportToFile(ruta + nombreArchivo);
                        conexion.Close();
                        cmd.Dispose();
                    }
                    catch (Exception) { }
                }
            }

            return(true);
        }
예제 #30
0
        private async void Backup()
        {
//            string constring = "Server=localhost;Port=3307;Database=projectx;Uid=root;Pwd=admin;charset=utf8";
//            string file = "C:\\backup.sql";

            SaveFileDialog fileDialog = new SaveFileDialog();

            fileDialog.Filter   = "Sql files (*.Sql)|*.Sql";
            fileDialog.FileName = "backup" + DateTime.Now.ToString("MM-dd-yyyy") + ".sql";
            var result = fileDialog.ShowDialog();

            if (result == false)
            {
                return;
            }
            await DialogHost.Show(new PleaseWaitView(), "RootDialog",
                                  delegate(object sender, DialogOpenedEventArgs args)
            {
                Task.Run(() =>
                {
                    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(fileDialog.FileName);
                                    conn.Close();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                }).ContinueWith((t, _) =>
                {
                    args.Session.UpdateContent(new SuccessView());
                }, null, TaskScheduler.FromCurrentSynchronizationContext());
            });
        }