Ejemplo n.º 1
0
        //=================================RESTORE===================================
        //===========================================================================

        private async void button4_Click(object sender, EventArgs e)
        {
            selected_databases.Clear();

            foreach (ColoredItem item in lb_pri_db.SelectedItems)
            {
                //    for (int iter=0; iter < lb_pri_db.SelectedItems.Count; iter++ )
                //{
                LSDB lsdb = new LSDB
                {
                    database_name    = item.Text.ToString(),
                    src_share_path   = tb_src_share.Text,
                    dest_share_path  = tb_dest_share.Text,
                    primary_server   = tb_primary.Text.Trim(),
                    secondary_server = tb_secondary.Text.Trim()
                };

                selected_databases.Add(lsdb);
            }

            button4.Enabled = false;

            m_oWorker_restore.RunWorkerAsync();
            //LogShipping ls = new LogShipping();

            ////string output =
            //await ls.restore_init_secondary(selected_databases,tb_primary.Text.Trim(), tb_secondary.Text.Trim(),tb_src_share.Text,tb_mdf_path.Text,tb_ldf_path.Text);

            //if (output != "")
            //{
            //    MessageBox.Show(output);
            //}
        }
Ejemplo n.º 2
0
        private void m_oWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // The sender is the BackgroundWorker object we need it to
            // report progress and check for cancellation.
            //NOTE : Never play with the UI thread here...

            selected_databases.Clear();

            foreach (ColoredItem item in lb_pri_db.SelectedItems)
            {
                //    for (int iter=0; iter < lb_pri_db.SelectedItems.Count; iter++ )
                //{
                LSDB lsdb = new LSDB
                {
                    database_name    = item.Text.ToString(),
                    src_share_path   = tb_src_share.Text,
                    dest_share_path  = tb_dest_share.Text,
                    primary_server   = tb_primary.Text.Trim(),
                    secondary_server = tb_secondary.Text.Trim()
                };

                selected_databases.Add(lsdb);
            }

            m_oWorker.ReportProgress(0);

            LogShipping ls = new LogShipping();

            //string output =
            //await

            ls.backup_init_primary(selected_databases, tb_primary.Text.Trim());

            if (m_oWorker.CancellationPending)
            {
                // Set the e.Cancel flag so that the WorkerCompleted event
                // knows that the process was cancelled.
                e.Cancel = true;
                m_oWorker.ReportProgress(0);
                return;
            }
            //Report 100% completion on operation completed
            m_oWorker.ReportProgress(100);
        }
Ejemplo n.º 3
0
        private void m_oWorker_restore_DoWork(object sender, DoWorkEventArgs e)
        {
            selected_databases.Clear();

            foreach (ColoredItem item in lb_pri_db.SelectedItems)
            {
                //    for (int iter=0; iter < lb_pri_db.SelectedItems.Count; iter++ )
                //{
                LSDB lsdb = new LSDB
                {
                    database_name    = item.Text.ToString(),
                    src_share_path   = tb_src_share.Text,
                    dest_share_path  = tb_dest_share.Text,
                    primary_server   = tb_primary.Text.Trim(),
                    secondary_server = tb_secondary.Text.Trim()
                };

                selected_databases.Add(lsdb);
            }

            LogShipping ls = new LogShipping();

            //string output =
            // await ls.restore_init_secondary(selected_databases, tb_primary.Text.Trim(), tb_secondary.Text.Trim(), tb_src_share.Text, tb_mdf_path.Text, tb_ldf_path.Text);

            m_oWorker_restore.ReportProgress(0);

            ls.restore_init_secondary(selected_databases, tb_primary.Text.Trim(), tb_secondary.Text.Trim(), tb_src_share.Text, tb_mdf_path.Text, tb_ldf_path.Text);

            if (m_oWorker_restore.CancellationPending)
            {
                // Set the e.Cancel flag so that the WorkerCompleted event
                // knows that the process was cancelled.
                e.Cancel = true;
                m_oWorker_restore.ReportProgress(0);
                return;
            }
            //Report 100% completion on operation completed
            m_oWorker_restore.ReportProgress(100);
        }
Ejemplo n.º 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            string list_selected_db_pri = "";
            //list_selected_db_pri += lb_pri_db.SelectedItem.ToString();
            string command_sql = "";

            //string command_backup_init = "";

            //string command_restore_init = "";

            foreach (ColoredItem item in lb_pri_db.SelectedItems)
            {
                //    for (int iter=0; iter < lb_pri_db.SelectedItems.Count; iter++ )
                //{
                LSDB lsdb = new LSDB
                {
                    database_name    = item.Text.ToString(),
                    src_share_path   = tb_src_share.Text,
                    dest_share_path  = tb_dest_share.Text,
                    primary_server   = tb_primary.Text.Trim(),
                    secondary_server = tb_secondary.Text.Trim()
                };

                selected_databases.Add(lsdb);

                list_selected_db_pri += item.Text.ToString() + "\r\n";

                if (lb_pri_db.SelectedItems.IndexOf(item) == lb_pri_db.SelectedItems.Count - 1)
                {
                    command_sql += "('" + item.Text.ToString() + "','" + tb_loc_fld.Text + "','" + tb_src_share.Text + "','" + tb_dest_share.Text + "'," + tb_time_offset.Text + ")";
                    //command_backup_init += "BACKUP DATABASE ["+ item.Text.ToString() + "] TO DISK = ''" + tb_src_share.Text+"\\FULL_INIT_"+ item.Text.ToString()+".bak'' WITH CHECKSUM, FORMAT, INIT, STATS = 10; ";
                    //command_restore_init += "RESTORE DATABASE [" +item.Text.ToString() + "] FROM DISK = ''" + tb_src_share.Text + "\\FULL_INIT_" + item.Text.ToString() + ".bak''  WITH CHECKSUM, MOVE ["+ item.Text.ToString() + "] TO ''"+tb_mdf_path.Text+"\\"+ item.Text.ToString() + "_Data.mdf'', MOVE ''"+item.Text.ToString() +"_Log'' TO ''"+tb_ldf_path.Text+"\\" + item.Text.ToString() + "_Log.ldf'', NORECOVERY, REPLACE, STATS = 10; ";
                }
                else
                {
                    command_sql += "('" + item.Text.ToString() + "','" + tb_loc_fld.Text + "','" + tb_src_share.Text + "','" + tb_dest_share.Text + "'," + tb_time_offset.Text + "),";
                    //command_backup_init += "BACKUP DATABASE [" + item.Text.ToString() + "] TO DISK = ''" + tb_src_share.Text + "\\FULL_INIT_" + item.Text.ToString() + ".bak'' WITH CHECKSUM, FORMAT, INIT, STATS = 10; ";
                    //command_restore_init += "RESTORE DATABASE [" + item.Text.ToString() + "] FROM DISK = ''" + tb_src_share.Text + "\\FULL_INIT_" + item.Text.ToString() + ".bak''  WITH CHECKSUM, MOVE [" + item.Text.ToString() + "] TO ''" + tb_mdf_path.Text + "\\" + item.Text.ToString() + "_Data.mdf'', MOVE ''" + item.Text.ToString() + "_Log'' TO ''" + tb_ldf_path.Text + "\\" + item.Text.ToString() + "_Log.ldf'', NORECOVERY, REPLACE, STATS = 10; ";
                }
                //}
            }

            if (list_selected_db_pri != "")
            {
                DialogResult dialogResult = MessageBox.Show("Для следующих баз будет настроен LogShipping\r\n Будут созданы задания в службе SQL Agent \r\n" + list_selected_db_pri, "Alert!", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    create_ls_on_primary(tb_primary.Text.Trim(), tb_primary.Text.Trim(), tb_secondary.Text.Trim(), command_sql, tb_freq_subday.Text.Trim(), tb_file_ret_pri.Text);

                    create_ls_on_secondary(tb_secondary.Text.Trim(), tb_primary.Text.Trim(), tb_secondary.Text.Trim(), tb_file_ret.Text.Trim(), tb_freq_subday.Text.Trim(), command_sql);
                }
            }
            else
            {
                MessageBox.Show("Выберите хотя бы одну базу для создания задния Log Shipping");
            }
            //var lst = lb_pri_db.SelectedItems.Cast<DataRowView>();
            //foreach (var item in lst)
            //{
            //    MessageBox.Show(item.Row[0].ToString());// Or Row[1]...
            //}

            //MessageBox.Show(list_selected_db_pri);
        }