Ejemplo n.º 1
0
        public Exception Excute_Restore_DB(Info_MySQL_Instansce instansce)
        {
            try
            {
                string constring = "server=" + instansce.Server_Name + ";port=" + instansce.Port + ";user="******";pwd=" + instansce.Pass + ";";
                string file      = AppDomain.CurrentDomain.BaseDirectory + DBSource + ".sql";
                using (MySqlConnection conn = new MySqlConnection(constring))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();
                            cmd.CommandText = "DROP DATABASE IF EXISTS " + DBTarget + "; Create database " + DBTarget;
                            cmd.ExecuteNonQuery();
                            conn.Close();

                            constring = "server=" + instansce.Server_Name + ";port=" + instansce.Port + ";user="******";pwd=" + instansce.Pass + ";database=" + DBTarget + ";";

                            conn.ConnectionString = (constring);

                            conn.Open();
                            mb.ImportFromFile(file);
                            conn.Close();
                        }
                    }
                }
            }
            catch (Exception op)
            {
                return(new Exception(op.Message, op.InnerException));
            }
            return(null);
        }
Ejemplo n.º 2
0
        public Exception Execute_DB(Info_MySQL_Instansce instansce)
        {
            try
            {
                string constring = "server=" + instansce.Server_Name + ";port=" + instansce.Port + ";user="******";pwd=" + instansce.Pass + ";database=" + instansce.DB_Name + ";";

                string text = "";

                foreach (var i in Files)
                {
                    text = text + File.ReadAllText(i);
                }

                using (MySqlConnection conn = new MySqlConnection(constring))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        cmd.CommandText = text;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
            }
            catch (Exception op)
            {
                return(new Exception(op.Message, op.InnerException));
            }
            return(null);
        }
Ejemplo n.º 3
0
        private void timer_Tick(object sender, EventArgs e)
        {
            string date_time = DateTime.Now.ToString("HH:mm");

            for (int i = 0; i < info_DB.Count; i++)
            {
                if (date_time == info_DB[i].Time_Running)
                {
                    List <string> day_running = info_DB[i].DayOfWeed_Running.Split(',').ToList();

                    for (int j = 0; j < day_running.Count; j++)
                    {
                        if (DateTime.Now.DayOfWeek.ToString().ToLower() == day_running[j].ToLower())
                        {
                            Info_DB infoDB = info_DB[i];
                            new Thread(() => SQLServer_Running(infoDB, _Server)).Start();
                        }
                    }
                }
            }


            for (int i = 0; i < info_JobMySQL.Count; i++)
            {
                for (int k = 0; k < info_JobMySQL[i].ListDB.Count; k++)
                {
                    if (date_time == info_JobMySQL[i].ListDB[k].Time_Running)
                    {
                        List <string> day_running = info_JobMySQL[i].ListDB[k].DayOfWeed_Running.Split(',').ToList();

                        for (int j = 0; j < day_running.Count; j++)
                        {
                            if (DateTime.Now.DayOfWeek.ToString().ToLower() == day_running[j].ToLower())
                            {
                                Info_MySQL_DB        infoDB    = info_JobMySQL[i].ListDB[k];
                                Info_MySQL_Instansce instansce = info_JobMySQL[i].Instances;

                                new Thread(() => MySQL_Running(instansce, infoDB)).Start();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        bool MySQL_Running(Info_MySQL_Instansce instansce, Info_MySQL_DB DB)
        {
            string    Mess = "";
            Exception er   = null;  //gán cờ er bằng null chỉ thị ko có lỗi

            Thread.CurrentThread.IsBackground = true;

            er = DB.Download_BackupFile(fTPServer);
            if (er != null)
            {
                Mess = er.Message + ": " + ((er.InnerException == null) ? "" : er.InnerException.Message);
                File_Read_Write.Write_File(log_path, DateTime.Now + ": Error - " + DB.DBTarget + ": " + Mess, true);

                SendEmail.Send_Email(DB.Email, null, "[Dashboard - RTS] Clone Database error!", "Server: " + instansce.Server_Name + @"\nDatabase name: " + DB.DBTarget + "\n" + Mess, false);

                return(false);
            }
            else
            {
                File_Read_Write.Write_File(log_path, DateTime.Now + ": Download Backup file " + fTPServer.URL + "BackupDB_zip/" + DB.ServerSource + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + DB.DBSource + ".zip....done!", true);
            }


            er = DB.Excute_Restore_DB(instansce);
            if (er != null)
            {
                Mess = er.Message + ": " + ((er.InnerException == null) ? "" : er.InnerException.Message);
                File_Read_Write.Write_File(log_path, DateTime.Now + ": Error - " + DB.DBTarget + ": " + Mess, true);

                SendEmail.Send_Email(DB.Email, null, "[Dashboard - RTS] Clone Database error!", "Server: " + instansce.Server_Name + @"\nDatabase name: " + DB.DBTarget + "\n" + Mess, false);

                return(false);
            }
            else
            {
                File_Read_Write.Write_File(log_path, DateTime.Now + ": Restore " + DB.ServerSource + @"\" + DB.DBSource + " to " + instansce.Server_Name + @"\" + DB.DBTarget + " done!", true);
            }

            SendEmail.Send_Email(DB.Email, null, "[Dashboard - RTS] Clone Database succufully!", "Clone Database " + DB.ServerSource + @"\" + DB.DBSource + " to " + instansce.Server_Name + @"\" + DB.DBTarget + " succufully!", false);

            return(true);
        }