public FrmAddEditBackupItem()
 {
     InitializeComponent();
     bkpitm = new BackupItem();
     newItem = true;
     loadPasswords();
 }
 public FrmAddEditBackupItem(BackupItem itm)
 {
     InitializeComponent();
     bkpitm = itm;
     newItem = false;
     this.Text = lblHeader.Text = "Edit Backup Item";
     loadPasswords();
 }
Esempio n. 3
0
        //This checks both styles of connections and return false when the second(older) method ALSO fails
        //maybe should've done this with 2 separate methods but thought against it as those 2 new functions
        //would increase overhead and wouldn't be needed again.
        public static bool TestConnection(BackupItem itm)
        {
            //Begin NewStyle check
            MysqlAlias.MySqlConnection conn = null;
            try
            {
                conn = new MysqlAlias.MySqlConnection(itm.ConnectionString());
                conn.Open();
            }
            catch (MysqlAlias.MySqlException)
            {
                //Begin OldStyle Check
                OldMysqlAlias.MySqlConnection old_conn = null;

                try
                {
                    old_conn = new OldMysqlAlias.MySqlConnection(itm.ConnectionString());
                    old_conn.Open();
                }
                catch (MysqlAlias.MySqlException)
                {
                    return false;
                }catch(Exception)
                {
                    return false;
                }
                finally
                {
                    if (old_conn != null)
                    {
                        old_conn.Close();
                    }
                }
                //End OldStyle Check
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            //End NewStyle check
            return true;
        }
Esempio n. 4
0
        bool backupDatabase(BackupItem bk_itm)
        {
            //This uses the newer version of mysql dll 6.6 ot enable connection to servers that use new style password authemtication (4.1 style)

            string result_folder = bk_itm.SaveTo + "\\" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString("D2") + "-" + DateTime.Now.Day.ToString("D2") + "\\" + bk_itm.Database + "\\";

            MysqlAlias.MySqlConnection conn = null;
            MysqlAlias.MySqlDataReader rdr = null;

            try
            {
                conn = new MysqlAlias.MySqlConnection(bk_itm.ConnectionString());
                conn.Open();
                //get every table in this db
                string stm = "SHOW TABLES";
                MysqlAlias.MySqlCommand cmd = new MysqlAlias.MySqlCommand(stm, conn);
                rdr = cmd.ExecuteReader();

                //deal with directory that .sql files should be saved in
                if (!Directory.Exists(result_folder))
                {
                    Directory.CreateDirectory(result_folder);
                }

                string current_table = "";
                while (rdr.Read())
                {
                    current_table = rdr.GetString(0);
                    // Use ProcessStartInfo class
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.CreateNoWindow = true;
                    startInfo.UseShellExecute = false;
                    startInfo.FileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\mysqldump.exe";
                    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    //::@C:\Users\User\Downloads\MySQLWinBackup\MySQLWinBackup\mysqldump.exe
                    startInfo.Arguments = "--host=\"" + bk_itm.Host + "\" --port=\"" + bk_itm.Port + "\" --user=\"" + bk_itm.Username + "\" --password=\"" + bk_itm.PasswordValue + "\" -Q --result-file=\"" + result_folder + "\\" + current_table + ".sql\" \"" + bk_itm.Database + "\" \"" + current_table + "\"";

                    try
                    {
                        // Start the process with the info we specified.
                        // Call WaitForExit and then the using statement will close.
                        using (Process exeProcess = Process.Start(startInfo))
                        {
                            exeProcess.WaitForExit();
                            txtOutput.Text += "Database: " + bk_itm.Database + "   -  table: " + current_table + " done " + Environment.NewLine;
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLog(ex.Message);
                        return false;
                    }
                }
                //progressBar2.PerformStep();
                //if (progressBar2.Value >= progressBar2.Maximum)
                //{
                //    progressBar2.Style = ProgressBarStyle.Marquee;
                //}

            }
            catch (MysqlAlias.MySqlException ex)
            {
                ErrorLog(ex.Message);
                return false;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return true;
        }
Esempio n. 5
0
        private void loadBackupItems()
        {
            lstBkpItems.Clear();
            //loop through file and read lines
            List<string> lines = new List<string>();

            // 2
            // Use using StreamReader for disposing.
            using (StreamReader r = new StreamReader(configFile))
            {
                // 3
                // Use while != null pattern for loop
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    if (line.Split(new char[] { ' ' })[0].StartsWith("::"))
                    {
                        //ignore line as this is a comment
                    }
                    else
                    {
                        lines.Add(line);
                    }
                }
            }

            //now loop through list and backup dbs accordingly
            for (int indx = 0; indx < lines.Count; indx++)
            {
                string line = lines[indx];
                string[] split_line = line.Split(new char[] { ' ' });
                BackupItem bkpitm = new BackupItem();
                bkpitm.Host = split_line[0];
                bkpitm.Username = split_line[1];
                bkpitm.PasswordKey = split_line[2];
                if (lstDbPasswords.Any(pk => pk.PasswordKey == bkpitm.PasswordKey))
                {
                    bkpitm.PasswordValue = lstDbPasswords.First(p => p.PasswordKey == bkpitm.PasswordKey).PasswordValue;
                }else
                {
                    ErrorLog("No password found for: "+bkpitm.ToString());
                }
                bkpitm.Port = split_line[3];
                bkpitm.Database = split_line[4];
                bkpitm.SaveTo = split_line[5];

                lstBkpItems.Add(bkpitm);
            }

            bsBkpItems.ResetBindings(false);
        }