示例#1
0
        public BinlogDumpCredentialsConfig calculateDumpConfig()
        {
            BinlogDumpCredentialsConfig retConfig = config;
            //<binarylognames>
            MySQLCredentialsConfig myconfig = new MySQLCredentialsConfig();

            myconfig.host     = config.host;
            myconfig.port     = config.port;
            myconfig.username = config.username;
            myconfig.password = config.password;
            myconfig.database = config.database;
            DbConnection dbcon = new DbConnection(myconfig);

            retConfig.logfiles = dbcon.getBinlogfilenames().ToArray();
            //</binarylognames>
            int bpType = 1;

            if (retConfig.isIncrementalDelta)
            {
                bpType = 2;
            }
            try
            {
                string[] res = calculatePrefix(bpType);
                retConfig.prefix        = res[1];
                retConfig.startDateTime = res[0].Replace(',', ':'); //replacing : because it is invalid in filenames
                                                                    //retConfig.prefix += "_" + dbcon.getCurrentDatetime().Replace(':',',');
            }
            catch (Exception ex)
            {
                retConfig.prefix = "Error calculating filename prefix: " + ex.Message;
                Console.WriteLine(ex.StackTrace);
            }
            return(retConfig);
        }
示例#2
0
        /*
         * [mysqld] ubuntu mysql server config
         * default-time-zone='+02:00'
         * server-id               = 1
         * log_bin                 = /var/log/mysql/mysql-bin.log
         * log-bin-index           = /var/log/mysql/bin-log.index
         * expire_logs_days        = 30
         * max_binlog_size   = 100M
         * binlog_format=row
         *
         */


        private void performChecks()
        {
            if (config.locationIds == null || config.locationIds.Length == 0)
            {
                result.wasSuccessful = false;
                result.errorNumber   = -2;
                result.errorMessage  = "No save location set.";
                return;
            }

            IncrementalUtils iutils = new IncrementalUtils(config);

            config = iutils.calculateDumpConfig();
            if (config.logfiles == null || config.logfiles.Length == 0)
            {
                result.wasSuccessful = false;
                result.errorNumber   = -2;
                result.errorMessage  = "Binary log file names on server not set.";
                return;
            }
            if (config.logfiles[0] == "Error")
            {
                result.wasSuccessful = false;
                result.errorNumber   = -2;
                result.errorMessage  = config.logfiles[1];
                return;
            }
            if (config.prefix == null)
            {
                result.wasSuccessful = false;
                result.errorNumber   = -2;
                result.errorMessage  = "Filename prefix is null.";
                return;
            }
            if (config.prefix.StartsWith("Error"))
            {
                result.wasSuccessful = false;
                result.errorNumber   = -2;
                result.errorMessage  = config.prefix;
                return;
            }
            if (config.prefix.StartsWith("FB_0.0.0"))
            {
                result.wasSuccessful = false;
                result.errorNumber   = -2;
                result.errorMessage  = "No previous backups found in save locations. Unable to execute incremental backup.";
                return;
            }
        }
示例#3
0
文件: Home.cs 项目: CsPeitch/Firedump
        private void onCompletedHandler(DumpResultSet status)
        {
            if (status != null)
            {
                lStatus.Invoke((MethodInvoker) delegate() {
                    lStatus.Text = "Completed";
                });

                pbDumpExec.Invoke((MethodInvoker) delegate() {
                    pbDumpExec.Value = pbDumpExec.Maximum;
                });

                if (status.wasSuccessful)
                {
                    string prefix = null;
                    if (cIncrementalFormat.Checked)
                    {
                        this.Invoke((MethodInvoker) delegate()
                        {
                            List <int> locations = new List <int>();
                            foreach (ListViewItem item in lbSaveLocations.Items)
                            {
                                Object loc = item.Tag;
                                locations.Add(Convert.ToInt32(((firedumpdbDataSet.backup_locationsRow)loc).id));
                            }
                            BinlogDumpCredentialsConfig config = new BinlogDumpCredentialsConfig();
                            config.host     = (string)serverData.Rows[cmbServers.SelectedIndex]["host"];
                            config.port     = unchecked ((int)(long)serverData.Rows[cmbServers.SelectedIndex]["port"]);
                            config.username = (string)serverData.Rows[cmbServers.SelectedIndex]["username"];
                            config.password = (string)serverData.Rows[cmbServers.SelectedIndex]["password"];

                            List <string> databases      = new List <string>();
                            List <string> excludedTables = new List <string>();
                            tableList = new List <string>();
                            foreach (TreeNode node in tvDatabases.Nodes)
                            {
                                if (node.Checked)
                                {
                                    databases.Add(node.Text);
                                    string tables = "";
                                    foreach (TreeNode childNode in node.Nodes)
                                    {
                                        if (!childNode.Checked)
                                        {
                                            tables += childNode.Text + ",";
                                        }
                                        else
                                        {
                                            tableList.Add(childNode.Text);
                                        }
                                    }
                                    if (tables != "")
                                    {
                                        tables = tables.Substring(0, tables.Length - 1); //vgazei to teleutaio comma
                                    }
                                    excludedTables.Add(tables);
                                }
                            }
                            config.database         = databases[0];
                            config.locationIds      = locations.ToArray();
                            IncrementalUtils iutils = new IncrementalUtils(config);
                            prefix = iutils.calculatePrefix(0)[1];
                        });
                    }

                    saveToLocations(status.fileAbsPath, prefix);
                }
                else
                {
                    this.UseWaitCursor = false;
                    string errorMessage = "";
                    switch (status.errorNumber)
                    {
                    case -1:
                        errorMessage = "Connection credentials not set correctly:\n" + status.errorMessage;
                        Console.WriteLine(errorMessage);
                        break;

                    case -2:
                        errorMessage = "MySQL dump failed:\n" + status.mysqldumpexeStandardError;
                        Console.WriteLine(errorMessage);
                        break;

                    case -3:
                        errorMessage = "Compression failed:\n" + status.mysqldumpexeStandardError;
                        Console.WriteLine(errorMessage);
                        break;

                    default:
                        break;
                    }
                    MessageBox.Show(errorMessage, "Dump failed", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    bStartDump.Invoke((MethodInvoker) delegate()
                    {
                        bStartDump.Enabled = true;
                    });
                }

                //kiala pramata na kanei edo, afta pou meleges
                //
                //gia ui components xriazete Invoke
            }
            else
            {
                this.UseWaitCursor = false;
            }
        }
示例#4
0
文件: Home.cs 项目: CsPeitch/Firedump
        private void bStartDump_Click(object sender, EventArgs e)
        {
            if (!performChecks())
            {
                return;
            }
            if (adapter.isDumpRunning())
            {
                MessageBox.Show("dump is running...");
                return;
            }
            if (logadapter.isDumpRunning())
            {
                MessageBox.Show("dump is running...");
                return;
            }


            List <string> databases      = new List <string>();
            List <string> excludedTables = new List <string>();

            tableList = new List <string>();
            foreach (TreeNode node in tvDatabases.Nodes)
            {
                if (node.Checked)
                {
                    databases.Add(node.Text);
                    string tables = "";
                    foreach (TreeNode childNode in node.Nodes)
                    {
                        if (!childNode.Checked)
                        {
                            tables += childNode.Text + ",";
                        }
                        else
                        {
                            tableList.Add(childNode.Text);
                        }
                    }
                    if (tables != "")
                    {
                        tables = tables.Substring(0, tables.Length - 1); //vgazei to teleutaio comma
                    }
                    excludedTables.Add(tables);
                }
            }

            //testing

            /*
             * IncrementalUtils testutils = new IncrementalUtils();
             * List<string> chain = testutils.calculateChain("D:\\MyStuff\\Backups\\dumps\\test\\testdumpinc_IDB_0.2.2_2019-10-30 17,50,46", -1);
             * foreach (string chainfname in chain)
             * {
             *  Console.WriteLine("chain: "+chainfname);
             * }
             * bool b = true; //gia na mi vgazei unreachable code apo katw
             * if (b) return;*/
            /*
             * BinlogDumpCredentialsConfig configtest1 = new BinlogDumpCredentialsConfig();
             * configtest1.host = (string)serverData.Rows[cmbServers.SelectedIndex]["host"];
             * configtest1.port = unchecked((int)(long)serverData.Rows[cmbServers.SelectedIndex]["port"]);
             * configtest1.username = (string)serverData.Rows[cmbServers.SelectedIndex]["username"];
             * configtest1.password = (string)serverData.Rows[cmbServers.SelectedIndex]["password"];
             *
             * backuplocations = new List<firedumpdbDataSet.backup_locationsRow>();
             * List<int> locationIds1 = new List<int>();
             * foreach (ListViewItem item in lbSaveLocations.Items)
             * {
             *  Object loc = item.Tag;
             *  backuplocations.Add((firedumpdbDataSet.backup_locationsRow)loc);
             *  locationIds1.Add((int)((firedumpdbDataSet.backup_locationsRow)loc).id);
             * }
             * configtest1.locationIds = locationIds1.ToArray();
             * configtest1.isIncrementalDelta = true;
             * IncrementalUtils iutils = new IncrementalUtils(configtest1);
             * configtest1 = iutils.calculateDumpConfig();
             *
             * foreach (string logfile in configtest1.logfiles)
             * {
             *  Console.WriteLine(logfile);
             * }
             * Console.WriteLine("Next prefix: " + configtest1.prefix);
             * Console.WriteLine("StartDateTime: " + configtest1.startDateTime);
             * bool a = true; //gia na mi vgazei unreachable code apo katw
             * if (a) return;
             * // /testing*/

            if (cIncrementalFormat.Checked && databases.Count() > 1)
            {
                MessageBox.Show("Only one database may be selected with incremental format enabled.", "MySQL dump", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (databases.Count == 0)
            {
                MessageBox.Show("No database selected", "MySQL Dump", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!cIncrementalFormat.Checked || rbFull.Checked)
            {
                adapter = new MySqlDumpAdapter();
                DumpCredentialsConfig config = new DumpCredentialsConfig();
                config.host     = (string)serverData.Rows[cmbServers.SelectedIndex]["host"];
                config.port     = unchecked ((int)(long)serverData.Rows[cmbServers.SelectedIndex]["port"]);
                config.username = (string)serverData.Rows[cmbServers.SelectedIndex]["username"];
                config.password = (string)serverData.Rows[cmbServers.SelectedIndex]["password"];


                if (databases.Count == 1)
                {
                    config.database = databases[0];
                    if (excludedTables[0] != "")
                    {
                        config.excludeTablesSingleDatabase = excludedTables[0];
                    }
                }
                else
                {
                    databaseList         = databases;
                    config.database      = databases[0];
                    config.databases     = databases.ToArray();
                    config.excludeTables = excludedTables.ToArray();
                }

                pbDumpExec.Value = 0;

                bStartDump.Enabled = false;
                adapter.setTableList(tableList);

                adapter.Cancelled        += onCancelledHandler;
                adapter.Completed        += onCompletedHandler;
                adapter.CompressProgress += compressProgressHandler;
                adapter.CompressStart    += onCompressStartHandler;
                adapter.Error            += onErrorHandler;
                adapter.InitDumpTables   += initDumpTablesHandler;
                adapter.Progress         += onProgressHandler;
                adapter.TableRowCount    += tableRowCountHandler;
                adapter.TableStartDump   += onTableDumpStartHandler;

                this.UseWaitCursor = true;
                adapter.startDump(config);
            }
            else
            {
                logadapter = new BinlogDumpAdapter();
                BinlogDumpCredentialsConfig config = new BinlogDumpCredentialsConfig();
                config.host               = (string)serverData.Rows[cmbServers.SelectedIndex]["host"];
                config.port               = unchecked ((int)(long)serverData.Rows[cmbServers.SelectedIndex]["port"]);
                config.username           = (string)serverData.Rows[cmbServers.SelectedIndex]["username"];
                config.password           = (string)serverData.Rows[cmbServers.SelectedIndex]["password"];
                config.database           = databases[0]; //if here only one database is selected due to above checks
                config.isIncrementalDelta = rbIncDelta.Checked;

                backuplocations = new List <firedumpdbDataSet.backup_locationsRow>();
                List <int> locationIds = new List <int>();
                foreach (ListViewItem item in lbSaveLocations.Items)
                {
                    Object loc = item.Tag;
                    backuplocations.Add((firedumpdbDataSet.backup_locationsRow)loc);
                    locationIds.Add((int)((firedumpdbDataSet.backup_locationsRow)loc).id);
                }
                config.locationIds = locationIds.ToArray();

                pbDumpExec.Value   = 0;
                bStartDump.Enabled = false;

                logadapter.config = config;

                //handlers
                logadapter.Cancelled        += onCancelledHandler;
                logadapter.Completed        += onCompletedHandlerBinlog;
                logadapter.CompressProgress += compressProgressHandler;
                logadapter.CompressStart    += onCompressStartHandler;
                logadapter.Progress         += onProgressHandler;
                logadapter.Error            += onErrorHandler;
                //handlers

                this.UseWaitCursor = true;
                logadapter.startDump();
            }
        }
示例#5
0
 public IncrementalUtils(BinlogDumpCredentialsConfig config)
 {
     this.config      = config;
     this.locationIds = config.locationIds;
 }
示例#6
0
 public BinlogDumpAdapter(BinlogDumpCredentialsConfig config)
 {
     this.config = config;
 }