Exemplo n.º 1
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            this.StartInfo.WaitForBegin = this.checkBox_downloadFile.Checked;

            // 合成参数
            if (this.checkBox_startAtServerBreakPoint.Checked == true)
            {
                this.StartInfo.Start = "dbnamelist=continue";
            }
            else
            {
                // this.StartInfo.Start = BuildStart(this.textBox_dbNameList.Text.Replace("\r\n", ","));

                BackupTaskStart param = new BackupTaskStart();
                param.BackupFileName = this.comboBox_backupFileName.Text;
                param.DbNameList     = this.textBox_dbNameList.Text.Replace("\r\n", ",");

                this.StartInfo.Start = param.ToString();
            }

            // 通用启动参数
            this.StartInfo.Param = "";  // BuildTaskParam(this.comboBox_function.Text, false);

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 2
0
        private void StartBackupDialog_Load(object sender, EventArgs e)
        {
            this.comboBox_backupFileName.Items.Add(
                Program.MainForm.LibraryName + "_" + BackupTaskStart.GetDefaultBackupFileName());

            // 起始位置参数
            string strError = "";

            this.checkBox_downloadFile.Checked = this.StartInfo.WaitForBegin;

            try
            {
                BackupTaskStart param = BackupTaskStart.FromString(this.StartInfo.Start);
#if NO
                string strDbNameList = "";
                int    nRet          = ParseStart(this.StartInfo.Start,
                                                  out strDbNameList,
                                                  out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                Debug.Assert(strDbNameList != null, "");
                this.textBox_dbNameList.Text = strDbNameList.Replace(",", "\r\n");
#endif

                this.textBox_dbNameList.Text      = param.DbNameList?.Replace(",", "\r\n");
                this.comboBox_backupFileName.Text = param.BackupFileName;

#if NO
                // 通用启动参数
                string strFunction = "";

                nRet = ParseTaskParam(this.StartInfo.Param,
                                      out strFunction,
                                      out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                //if (string.IsNullOrEmpty(strFunction) == false)
                //    this.comboBox_function.Text = strFunction;
#endif

                return;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }

ERROR1:
            MessageBox.Show(this, strError);
        }
Exemplo n.º 3
0
        // 一次操作循环
        public override void Worker()
        {
            // 系统挂起的时候,不运行本线程
            if (this.App.ContainsHangup("LogRecover") == true)
            {
                return;
            }

            if (this.App.PauseBatchTask == true)
            {
                return;
            }

            // REDO_TASK:
            try
            {
                string strError = "";
                int    nRet     = 0;

                if (this.App.LibraryCfgDom == null ||
                    this.App.LibraryCfgDom.DocumentElement == null)
                {
                    return;
                }

                BatchTaskStartInfo startinfo = this.StartInfo;
                if (startinfo == null)
                {
                    startinfo = new BatchTaskStartInfo();   // 按照缺省值来
                }
                BackupTaskStart param         = BackupTaskStart.FromString(startinfo.Start);
                string          strDbNameList = param.DbNameList;
#if NO
                string strDbNameList = "";
                int    nRet          = ParseStart(startinfo.Start,
                                                  out strDbNameList,
                                                  out strError);
                if (nRet == -1)
                {
                    this.AppendResultText("启动失败: " + strError + "\r\n");
                    return;
                }
#endif

                // 下一次 loop 进入的时候自动就是 continue (从断点继续)
                startinfo.Start = "";

#if NO
                //
                string strFunction = "";
                nRet = ParseTaskParam(startinfo.Param,
                                      out strFunction,
                                      out strError);
                if (nRet == -1)
                {
                    this.AppendResultText("启动失败: " + strError + "\r\n");
                    return;
                }
#endif

                // if (String.IsNullOrEmpty(strDbNameList) == true)
                if (strDbNameList == "continue")
                {
                    // 从断点继续循环
                    strDbNameList = "continue";
                }

                string strRecPathFileName = Path.Combine(this.App.BackupDir, "recpath.txt");
                string strBackupFileName  = "";

                if (string.IsNullOrEmpty(param.BackupFileName) == true)
                {
                    strBackupFileName = Path.Combine(this.App.BackupDir, this.App.LibraryName + "_" + BackupTaskStart.GetDefaultBackupFileName());
                }
                else
                {
                    strBackupFileName = Path.Combine(this.App.BackupDir, CanonializeBackupFileName(param.BackupFileName));
                }

                // 构造用于复制然后同步的断点信息
                // BreakPointCollection all_breakpoints = BreakPointCollection.BuildFromDbNameList(strDbNameList, strFunction);

                // 进行处理
                BreakPointInfo breakpoint = null;

                this.AppendResultText("*********\r\n");

                RmsChannel channel = this.RmsChannels.GetChannel(this.App.WsUrl);

                if (strDbNameList == "continue")
                {
                    // 按照断点信息处理
                    this.AppendResultText("从上次断点位置继续\r\n");

                    // return:
                    //      -1  出错
                    //      0   没有发现断点信息
                    //      1   成功
                    nRet = ReadBreakPoint(out breakpoint,
                                          out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                    if (nRet == 0)
                    {
                        // return;
                        // TODO: 此时如何让等待结束?并且返回启动出错信息
                        goto ERROR1;
                    }

                    strBackupFileName = breakpoint.BackupFileName;
                    if (string.IsNullOrEmpty(strBackupFileName))
                    {
                        strError = "从上次断点开始运行时,发现 BackupFileName 为空,只好放弃运行";
                        goto ERROR1;
                    }

                    // WriteStateFile(strBackupFileName, "creating");  // 表示文件正在创建中
                    PrepareBackupFileName(strBackupFileName, true);
                    this.AppendResultText("(从断点继续)本次大备份文件为 " + strBackupFileName + "\r\n");
                }
                else
                {
                    {
                        BreakPointInfo temp_breakpoint = null;
                        // 删除上次的大备份文件
                        // return:
                        //      -1  出错
                        //      0   没有发现断点信息
                        //      1   成功
                        nRet = ReadBreakPoint(out temp_breakpoint,
                                              out strError);
                        if (nRet == -1)
                        {
                            goto ERROR1;
                        }
                        if (nRet == 1)
                        {
                            string strLastBackupFileName = temp_breakpoint.BackupFileName;
                            if (string.IsNullOrEmpty(strLastBackupFileName) == false)
                            {
                                DeleteDataFiles(strLastBackupFileName);

                                this.AppendResultText("自动删除上次创建的大备份文件 " + strLastBackupFileName + "\r\n");
                            }
                        }
                        temp_breakpoint = null;
                    }

                    // 先从远端复制整个数据库,然后从开始复制时的日志末尾进行同步
                    this.AppendResultText("指定的数据库\r\n");

                    DeleteDataFiles(strBackupFileName);

                    PrepareBackupFileName(strBackupFileName, false);
                    this.AppendResultText("本次大备份文件为 " + strBackupFileName + "\r\n");

                    // 采纳先前创建好的复制并继续的断点信息
                    // breakpoints = all_breakpoints;

                    // 建立数据库定义文件
                    {
                        string strDefFileName = GetDatabaseDefFileName(strBackupFileName);
                        nRet = CreateDatabaseDefFile(channel,
                                                     strDbNameList,
                                                     strDefFileName,
                                                     out strError);
                        if (nRet == -1)
                        {
                            this.AppendResultText("创建数据库定义文件失败: " + strError + "\r\n");
                            WriteStateFile(strDefFileName, null);  // 表示文件创建出错
                            return;
                        }
                    }

                    // 建立要获取的记录路径文件
                    nRet = CreateRecPathFile(channel,
                                             strDbNameList,
                                             strRecPathFileName,
                                             out strError);
                    if (nRet == -1)
                    {
                        this.AppendResultText("创建记录路径文件失败: " + strError + "\r\n");
                        WriteStateFile(strBackupFileName, null);  // 表示文件创建出错
                        return;
                    }
                }

                // Debug.Assert(breakpoints != null, "");

                this.AppendResultText("计划进行的处理:\r\n---\r\n"
                                      + (breakpoint == null ? "备份全部数据库" : breakpoint.GetSummary())
                                      + "\r\n---\r\n\r\n");

                m_nRecordCount = 0;

                BreakPointInfo output_breakpoint = null;

                // for (int i = 0; i < breakpoints.Count; i++)
                {
                    // BreakPointInfo info = breakpoints[i];

                    // return:
                    //      -1  出错
                    //      0   处理被中断
                    //      1   成功
                    nRet = BackupDatabase(
                        channel,
                        strRecPathFileName,
                        breakpoint,
                        strBackupFileName,
                        out output_breakpoint,
                        out strError);

                    if (nRet == -1 || nRet == 0)
                    {
                        // 保存断点文件
                        SaveBreakPoint(output_breakpoint, true);
                        goto ERROR1;
                    }

                    // breakpoints.Remove(info);
                    // i--;

                    // 保存断点文件
                    SaveBreakPoint(output_breakpoint, false);

                    try
                    {
                        File.Delete(strRecPathFileName);
                    }
                    catch
                    {
                    }
                }

                // TODO: 如果集合为空,需要删除断点信息文件
                // 正常结束,复位断点
                if (this.StartInfos.Count == 0)
                {
                    // this.App.RemoveBatchTaskBreakPointFile(this.Name);
                    this.ClearTask();
                }

                this.StartInfo.Start = "";

                // AppendResultText("针对消息库 " + strMessageDbName + " 的循环结束。共处理 " + nRecCount.ToString() + " 条记录。\r\n");

                // TODO: 在断点文件中记载 StartInfos 内容

                this.AppendResultText("大备份结束。结果在文件 " + strBackupFileName + " 中\r\n");

#if NO
                {
                    // return:
                    //      -1  出错
                    //      0   没有发现断点信息
                    //      1   成功
                    nRet = ReadBreakPoint(out breakpoints,
                                          out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }

                    // 如果有累积的任务,还需要继续执行
                    if (nRet == 1 && this.StartInfos.Count > 0)
                    {
                        this.StartInfo = this.StartInfos[0];
                        this.StartInfos.RemoveAt(0);
                        goto REDO_TASK;
                    }
                }
#endif

                DoPendingCommands(strBackupFileName);
                return;

ERROR1:
                this.ErrorInfo = strError;
                this.AppendResultText(strError + "\r\n");
                this.SetProgressText(strError);
                DoPendingCommands(strBackupFileName);
                return;
            }
            finally
            {
            }
        }