同步数据

C/S同步数据篇:

TODO:

关于同步数据篇:主要讲解理清业务思路,下一篇:同步数据(依据业务需求):【将数据库中sys_Menu数据添加到sys_Menu_Copy】

TODO:

1,表【sys_Menu_Copy】已存在数据,过滤

2,表【sys_Menu_Copy】未存在数据,添加

讲解篇:1,窗体设计器生成的代码2,后台cs代码:

1,窗体设计器生成的代码

namespace DataSynchronousBWokerUI
{
    partial class MainForm
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
            this.label = new System.Windows.Forms.Label();
            this.btStop = new System.Windows.Forms.Button();
            this.btStart = new System.Windows.Forms.Button();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.progressBar1 = new System.Windows.Forms.ProgressBar();
            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
            this.tableLayoutPanel1.SuspendLayout();
            this.SuspendLayout();
            //
            // label
            //
            this.label.AutoSize = true;
            this.label.Location = new System.Drawing.Point(170, 67);
            this.label.Name = "label";
            this.label.Size = new System.Drawing.Size(0, 12);
            this.label.TabIndex = 13;
            //
            // btStop
            //
            this.btStop.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.btStop.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btStop.BackgroundImage")));
            this.btStop.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btStop.Location = new System.Drawing.Point(212, 53);
            this.btStop.Name = "btStop";
            this.btStop.Size = new System.Drawing.Size(203, 44);
            this.btStop.TabIndex = 12;
            this.btStop.Text = "取消同步";
            this.btStop.Click += new System.EventHandler(this.btStop_Click);
            //
            // btStart
            //
            this.btStart.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.btStart.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btStart.BackgroundImage")));
            this.btStart.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btStart.Location = new System.Drawing.Point(3, 53);
            this.btStart.Name = "btStart";
            this.btStart.Size = new System.Drawing.Size(203, 44);
            this.btStart.TabIndex = 11;
            this.btStart.Text = "同步数据";
            this.btStart.Click += new System.EventHandler(this.btStart_Click);
            //
            // label4
            //
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(33, 143);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(0, 12);
            this.label4.TabIndex = 14;
            //
            // label5
            //
            this.label5.AutoSize = true;
            this.label5.Image = ((System.Drawing.Image)(resources.GetObject("label5.Image")));
            this.label5.Location = new System.Drawing.Point(122, 142);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(0, 12);
            this.label5.TabIndex = 15;
            //
            // label6
            //
            this.label6.AutoSize = true;
            this.label6.Image = ((System.Drawing.Image)(resources.GetObject("label6.Image")));
            this.label6.Location = new System.Drawing.Point(209, 142);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(0, 12);
            this.label6.TabIndex = 16;
            //
            // listBox1
            //
            this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.listBox1.BackColor = System.Drawing.Color.White;
            this.listBox1.ForeColor = System.Drawing.SystemColors.InactiveCaptionText;
            this.listBox1.FormattingEnabled = true;
            this.listBox1.ItemHeight = 12;
            this.listBox1.Location = new System.Drawing.Point(1, 57);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new System.Drawing.Size(417, 184);
            this.listBox1.TabIndex = 17;
            //
            // progressBar1
            //
            this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.progressBar1.Location = new System.Drawing.Point(1, 12);
            this.progressBar1.Name = "progressBar1";
            this.progressBar1.Size = new System.Drawing.Size(417, 30);
            this.progressBar1.TabIndex = 18;
            //
            // tableLayoutPanel1
            //
            this.tableLayoutPanel1.ColumnCount = 2;
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.Controls.Add(this.btStart, 0, 1);
            this.tableLayoutPanel1.Controls.Add(this.btStop, 1, 1);
            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 243);
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.RowCount = 2;
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(419, 100);
            this.tableLayoutPanel1.TabIndex = 19;
            //
            // MainForm
            //
            this.BackgroundImage = global::DataSynchronousBWokerUI.Properties.Resources._1234564578798798798797987987987987;
            this.ClientSize = new System.Drawing.Size(419, 343);
            this.Controls.Add(this.tableLayoutPanel1);
            this.Controls.Add(this.progressBar1);
            this.Controls.Add(this.listBox1);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "MainForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "测试:同步数据";
            this.tableLayoutPanel1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label;
        private System.Windows.Forms.Button btStop;
        private System.Windows.Forms.Button btStart;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.ListBox listBox1;
        private System.Windows.Forms.ProgressBar progressBar1;
        private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
    }
}

2,后台cs代码

1,定义线程名,线程开始标识,连接服务器成功标识,退出程序标识,源数据库,目标数据库

private Thread preg;//线程名
        private bool tureOfalse;//线程执行标识
        public bool conYes;//连接服务成功失败标识
        private bool one = false;//退出程序标识
        string strdbHipis = System.Configuration.ConfigurationManager.AppSettings["NewHmFrameWork_QHS_SQ"].ToString();//源数据库
        //string strdbPreg = System.Configuration.ConfigurationManager.AppSettings["NewHmFrameWork_QHS_SQ_QingHai"].ToString();//目标数据库
        string strdbPreg = System.Configuration.ConfigurationManager.ConnectionStrings["NewHmFrameWork_QHS_SQ"].ToString();//目标数据库

2,主方法实行调用:

public MainForm()
        {
            InitializeComponent();
            btStop.Enabled = false;//未开启进程,不允许取消进程
            //委托
            InitTrayIcon();//图标托盘委托
            Control.CheckForIllegalCrossThreadCalls = false;//线程委托
            this.FormClosing += new FormClosingEventHandler(form_Closing);//退出程序委托
        }

3,图标声明

//图标声明
        NotifyIcon trayIcon = new NotifyIcon();
        //图标路径C:\Users\Administrator\Desktop\DataSynchronousBWokerUI\DataSynchronousBWokerUI\Images\_net_32.ico
        private Icon mNetTrayIcon = new Icon("..//Images//_net_32.ico");

4,线程开始

//线程开始
        private void btStart_Click(object sender, EventArgs e)
        {
            tureOfalse = true;
            preg = new Thread(new ThreadStart(PREG));
            preg.Start();

            btStart.Enabled = false;
            btStop.Enabled = true;
        }

5,线程方法

//线程方法
        private void PREG()
        {
            do
            {
                listBox1.Items.Add("正在连接源数据库... ...!");
                listBox1.Items.Add("正在连接目标数据库... ...!");
                ISopenCon();
            } while (!conYes);
            DoWork_select();
        }

6,线程停止

//线程停止
        private void btStop_Click(object sender, EventArgs e)
        {
            tureOfalse = false;
            preg.Abort();
            /*2015/2/2 调整:点击[取消同步],清空listbox当前数据*/
            this.listBox1.Items.Clear();
            listBox1.Items.Add("待同步... ...");
            //控件显示隐藏

            btStart.Enabled = true;
            btStop.Enabled = false;
        }

7,连接目标数据库失败将信息写入LOG

/// <summary>
        /// 连接目标数据库失败将信息写入LOG
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fslog(Exception ex)
        {
            string filepath = DateTime.Now.ToString("yyyyMMdd") + ".log";
            FileStream fs = new FileStream(filepath, FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            DateTime time = DateTime.Now;
            sw.WriteLine(time);
            //sw.WriteLine("连接目标数据库失败");
            sw.WriteLine(ex.Message);
            sw.WriteLine("---------------------------------------------------------");
            sw.Close();
            fs.Close();
        }

8,尝试连接源、目标数据库

/// <summary>
        /// 尝试连接源、目标数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ISopenCon()
        {

            try
            {
                SqlConnection conhipis = new SqlConnection(strdbHipis);
                conhipis.Open();
                conYes = true;
                conhipis.Close();
                SqlConnection conPreg = new SqlConnection(strdbPreg);
                conPreg.Open();
                conYes = true;
                conPreg.Close();

            }
            catch (Exception ex)
            {
                conYes = false;
                fslog(ex);
                listBox1.Items.Add("连接数据库失败......");
                Thread.Sleep(60000);
            }

        }

9,尝试删除目标数据库

/// <summary>
        /// 尝试删除目标数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DelPreg()
        {

            //try
            //{
            //bool delResult = true;
            ////插入数据之前,先删除当前社区的已有数据
            //string strDelSQL = "delete from dbo.sys_Menu ";
            //strDelSQL += "delete from dbo.sys_MenuInRoles ";
            //strDelSQL += "delete from dbo.sys_UsersInRoles ";
            //delResult = ExecuteSql(strDelSQL);
            //if (delResult == false)
            //{
            //    //this.label4.Text = "删除目标数据库失败......";
            //    listBox1.Items.Add("删除目标数据库失败......");
            //}
            //else
            //{
            //    //this.label4.Text = "删除目标数据库成功......";
            //    listBox1.Items.Add("删除目标数据库成功......");
            //}

            /*测试数据:删除dbo.sys_Menu_Copy在测试期间录入的数据便于二次录入<多次录入>*/
            SqlConnection hipiscon;
            SqlCommand SQLcom;
            hipiscon = new SqlConnection(strdbHipis);
            string strDelSQL = "delete from dbo.sys_Menu_Copy ";
            SQLcom = new SqlCommand(strDelSQL, hipiscon);
            try
            {
                hipiscon.Open();
                SQLcom.ExecuteNonQuery();
                hipiscon.Close();
                listBox1.Items.Add("删除目标数据库成功......");
            }
            catch (Exception ex)
            {
                listBox1.Items.Add("删除目标数据库失败......");
                fslog(ex);
                //Thread.Sleep(300000);
            }
            //}
            //catch (Exception ex)
            //{
            //    conYes = false;
            //    fslog(ex);
            //    listBox1.Items.Add("删除目标数据库失败......");
            //    Thread.Sleep(60000);
            //}
        }

10,对源库操作,对目标库操作

/// <summary>
        /// 对源库操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private DataTable IsOpenDT(string strSQL, string strConn)
        {
            SqlConnection hipiscon;
            SqlCommand SQLcom;
            DataTable DT;
            SqlDataAdapter SQLADA;
            hipiscon = new SqlConnection(strConn);
            SQLcom = new SqlCommand(strSQL, hipiscon);
            try
            {
                hipiscon.Open();
                SQLcom.ExecuteNonQuery();
                conYes = true;
                hipiscon.Close();
            }
            catch (Exception ex)
            {
                conYes = false;
                fslog(ex);
                //Thread.Sleep(300000);
            }
            DT = new DataTable();
            SQLADA = new SqlDataAdapter(SQLcom);
            SQLADA.Fill(DT);
            return DT;
        }
        /// <summary>
        /// 对目标库操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void IsOpen(string strsql, string strconn)
        {
            try
            {
                SqlConnection pregcon = new SqlConnection(strconn);
                SqlCommand sqlcom = new SqlCommand(strsql, pregcon);
                pregcon.Open();
                sqlcom.ExecuteNonQuery();
                conYes = true;
                pregcon.Close();

            }
            catch (Exception ex)
            {
                conYes = false;
                fslog(ex);
                //Thread.Sleep(300000);
            }
        }

11,具体操作方法

/// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="sender"></param>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DoWork_select()
        {

            //string strtb = System.Configuration.ConfigurationManager.AppSettings["strtable"].ToString();
            //string strupdt = System.Configuration.ConfigurationManager.AppSettings["updt"].ToString();
            //string strwhere = System.Configuration.ConfigurationManager.AppSettings["where"].ToString();

            while (tureOfalse)
            {
                ISopenCon();
                /*2015/2/2 调整:不能把菜单全部删除,没有的添加到服务器上去,已存在的过滤掉*/
                //DelPreg();
                //DataTable dt = IsOpenDT(strSQL, strdbHipis);

                //String[] tablenamekey = new String[3] { "dbo.sys_Menu", "dbo.sys_MenuInRoles", "dbo.sys_UsersInRoles" };//源数据库
                //String[] tablenamekeypreg = new String[3] { "dbo.sys_Menu_Copy", "dbo.sys_MenuInRoles_Copy", "dbo.sys_UsersInRoles_Copy" };//目标数据库

                //测试数据
                String[] tablenamekey = new String[1] { "dbo.sys_Menu" };//源数据库
                String[] tablenamekeypreg = new String[1] { "dbo.sys_Menu_Copy" };//目标数据库
                if (tablenamekey.Length > 0)
                {
                    for (int i = 0; i < tablenamekey.Length; i++)
                    {
                        string strtablenamekey = tablenamekey[i];
                        string strSQL1 = "select * from ";
                        strSQL1 += strtablenamekey;
                        strSQL1 += " where (1=1)";

                        insert_OR_update(strdbHipis, ref strSQL1, tablenamekeypreg[i]);
                    }
                }
            }
        }

        /// <summary>
        /// 插入,更新 最新数据到PIS数据库
        /// </summary>
        /// <param name="con">需要更新的表的连接字符串</param>
        /// <param name="lastSQL">最后SQL语句</param>
        /// <param name="tbName">需要操作的表</param>
        private void insert_OR_update(string strdbHipis, ref string strSQL, string tbName)
        {
            int a = 0;
            int b = 0;
            string lastSQL;
            DataTable dttb;
            DataTable dttb1;
            dttb = IsOpenDT(strSQL, strdbHipis);

            /*2015/2/2 调整:新增[进度条]追加显示加载信息*/
            progressBar1.Maximum = dttb.Rows.Count;//设置最大长度值
            progressBar1.Value = 0;//设置当前值
            progressBar1.Step = 1;//设置每次增长1条数据

            listBox1.Items.Add("连接源数据库成功......");
            listBox1.Items.Add("连接目标数据库成功......");
            listBox1.Items.Add("正在同步... ...");
            try
            {
                for (int i = 0; i < dttb.Rows.Count; i++)//根据判断条件循环更新数据库中的信息
                {
                    /*2015/2/2 调整:不能把菜单全部删除,没有的添加到服务器上去,已存在的过滤掉*/
                    lastSQL = "select * from " + tbName + " where sCode= '" + dttb.Rows[i][0].ToString().Trim() + "'";
                    //更新dttb1:一条记录 判断是否存在<过滤:新增>
                    /*测试数据库:源库和目标库一致 后期调整目标库连接字符串*/
                    dttb1 = IsOpenDT(lastSQL, strdbPreg);
                    //目标库中存在一条数据 取消
                    if (dttb1 != null && dttb1.Rows.Count > 0)
                    {
                        a = a + 1;
                        listBox1.Items.Add("已过滤" + a.ToString() + "条!");
                    }
                    else
                    {
                        string valuse = "";
                        string allcolumName = "";
                        for (int j = 0; j < dttb1.Columns.Count; j++)
                        {
                            if (j == dttb1.Columns.Count - 1)
                            {
                                allcolumName += dttb1.Columns[j].ColumnName.ToString();
                            }
                            else
                            {
                                allcolumName += dttb1.Columns[j].ColumnName.ToString() + ",";
                            }
                        }

                        //如果在线库中的时间为空则进行插入操作

                        for (int j = 0; j < dttb.Columns.Count; j++)
                        {
                            if (j == dttb.Columns.Count - 1)
                            {
                                valuse += "'" + dttb.Rows[i][j].ToString() + "'";
                            }
                            else
                            {
                                valuse += "'" + dttb.Rows[i][j] + "',";
                            }
                        }

                        lastSQL = "insert into " + tbName + " (" + allcolumName + ") values (" + valuse + ")";

                        IsOpen(lastSQL, strdbPreg);
                        b = b + 1;
                        listBox1.Items.Add("已插入" + b.ToString() + "条!");
                    }
                    /*2015/2/2 调整:新增[进度条]追加显示加载信息*/
                    progressBar1.Value += progressBar1.Step;//让进度条增加一次
                }
            }
            catch (Exception ex)
            {
                fslog(ex);
            }
            if ((a + b) > 0)
            {
                listBox1.Items.Add(tbName + "成功过滤" + a + "条数据条数据,成功插入" + b + "条数据!");
                listBox1.Items.Add(tbName + "同步数据成功!");
                //tureOfalse = false;
                preg.Abort();//线程执行标识:同步成功 关闭线程
                //UPINlog(a, b, tbName);
            }
            else
            {
                listBox1.Items.Add("");
            }

        }

12,此段代码相当于sqlhelper.cs功能【连接数据库】:

/// <summary>
        /// 执行SQL语句
        /// </summary>
        /// <param name="SQLString">SQL语句</param>
        /// <returns>bool值,成功返回true,失败返回false</returns>
        public static bool ExecuteSql(string SQLString)
        {
            bool isSucc = false;
            using (SqlConnection connection = new SqlConnection("Data Source=192.168.44.161;Initial Catalog=NewHmFrameWork_QHS_SQ_QingHai;Persist Security Info=True;User ID=sa;Password=jqkj123$%^;"))
            {
                connection.Open();

                using (SqlTransaction trans = connection.BeginTransaction())
                {
                    using (SqlCommand cmd = new SqlCommand(SQLString, connection))
                    {

                        cmd.Transaction = trans;
                        int rows = cmd.ExecuteNonQuery();
                        trans.Commit();
                        isSucc = true;

                    }
                }

            }
            return isSucc;
        }

13,初始化托盘图标

/// <summary>
        /// 初始化托盘图标
        /// </summary>
        public void InitTrayIcon()
        {

            // 设置托盘图标的菜单
            trayIcon.Icon = mNetTrayIcon;
            trayIcon.Text = "单击最大化程序";
            trayIcon.Visible = true;
            trayIcon.Click += new EventHandler(trayIcon_Click);
            MenuItem[] mnuItems = new MenuItem[4];
            mnuItems[0] = new MenuItem();
            mnuItems[0].Text = "显示";
            mnuItems[0].Click += new EventHandler(Item0_Click);

            mnuItems[1] = new MenuItem();
            mnuItems[1].Text = "隐藏";
            mnuItems[1].Click += new EventHandler(Item1_Click);

            mnuItems[2] = new MenuItem("-");

            mnuItems[3] = new MenuItem();
            mnuItems[3].Text = "退出程序";
            mnuItems[3].Click += new EventHandler(Item3_Click);
            trayIcon.ContextMenu = new ContextMenu(mnuItems);
        }

14,显示窗体,隐藏窗体,退出事件,点击托盘图标,单击X退出程序,

/// <summary>
        /// 显示窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Item0_Click(object sender, EventArgs e)
        {
            this.Show();

        }

        /// <summary>
        /// 隐藏窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Item1_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.trayIcon.ShowBalloonTip(5, "提示", "单击最大化程序", ToolTipIcon.Info);
        }

        /// <summary>
        /// 退出事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Item3_Click(object sender, EventArgs e)
        {

            preg.Abort();
            Application.Exit();
        }

        /// <summary>
        /// 点击托盘图标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void trayIcon_Click(object sender, EventArgs e)
        {
            this.Visible = true;
            this.WindowState = FormWindowState.Maximized;

        }
        /// <summary>
        /// 单击X退出程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void form_Closing(object sender, FormClosingEventArgs e)
        {
            if (one == false)
            {
                DialogResult dia = MessageBox.Show("是否真的退出程序!", " ", MessageBoxButtons.OKCancel);
                if (dia == DialogResult.Cancel)
                {
                    e.Cancel = true;
                    this.Show();
                    this.trayIcon.Visible = true;
                }
                if (dia == DialogResult.OK)
                {
                    one = true;
                    /*2015/2/2 调整:退出[未同步时,直接退出]*/
                    preg = new Thread(new ThreadStart(PREG));
                    preg.Start();
                    preg.Abort();
                    Application.Exit();
                }
            }
        }

时间: 2024-10-10 08:36:34

同步数据的相关文章

MySQL向redis同步数据

##创建表及数据 CREATE TABLE events_all_time ( id int(11) unsigned NOT NULL AUTO_INCREMENT, action varchar(255) NOT NULL, count int(11) NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE KEY uniq_action (action) ); insert into events_all_time(action,count) values

十八、Rsync 远程同步数据

在linux系统下数据备份的工具.Rsync不仅可以远程同步数据(类似于scp [1]),当然还可以本地同步数据(类似于cp),但不同于cp或scp的一点是,rsync不像cp/scp一样会覆盖以前的数据(如果数据已经存在),它会先判断已经存在的数据和新数据有什么不同,只有不同时才会把不同的部分覆盖掉.如果你的linux没有rsync命令请使用 yum install -y rsync 安装. 下面阿铭先举一个例子,然后再详细讲解rsync的用法: [[email protected] ~]#

zookeeper源码分析三LEADER与FOLLOWER同步数据流程

根据二)中的分析,如果一台zookeeper服务器成为集群中的leader,那么一定是当前所有服务器中保存数据最多的服务器,所以在这台服务器成为leader之后,首先要做的事情就是与集群中的其它服务器(现在是follower)同步数据,保证大家的数据一致,这个过程完毕了才开始正式处理来自客户端的连接请求. 首先来看Leader做的工作:二)中提到的同步数据时使用的逻辑时钟,它的初始值是0,每次选举过程都会递增的,在leader正式上任之后做的第一件事情,就是根据当前保存的数据id值,设置最新的逻

2-3-2 rsync+inotify备份同步数据

RSYNC = Remote Sync 远程同步 高效,一定要结合shell 官网:https://rsync.samba.org Author: Andrew Tridgell, Wayne Davison, and others Andrew Tridgell是Samba项目的领导者和主要开发人员,同时还在参与开发rsync\Linux Kernel. 与SCP的比较:scp=无法备份大量数据,类似windows的复制 rsync=边复制 ,边统计,边比较 Rsync特性和优点 可以镜像保存

Sql2008 r2 使用ftp 公布和订阅方式同步数据

Sql2008 r2使用公布和订阅方式同步数据 因为非常多图片 本篇没有图片 详情能够进入下载页  http://download.csdn.net/download/yefighter/7603741 1:公布服务器:公布方 sql2008 r2 iis7.5 windows server 2008 请登入服务器进行操作 不要用sqlserver远程连接 必须开启sqlserver agent服务以及开机自己主动启动 右键属性 打开sqlserver 点击新建本地公布 第一次公布的时候 会提示

(四)redis 主从同步数据

主从架构可以本机多实例数据库之间实现,也可以异机多实例之间实现. 主可读可写,备只读,这样就可以实现读写分离的架构. redis主从复制的特点: 1.一台master可以拥有多个slave(1对多的关系) 2.多个slave可以连接同一个master外,还可以连接到其他slave 这样做的原因是,如果master 挂掉之后,其中的一台slave立马可以充当master 的角色 整个服务流程可以不受影响 3.复制过程不会阻塞master,在同步数据的同时,master可以继续处理client请求.

多学一点(十四)——服务器间通过rsync和inotify-tools动态同步数据

Linux 下的 rsync 命令非常强大,多用来同步不同服务器上的数据同步.以前我们通常使用 crond 来实现,但 crond 很难做到实时同步.下面介绍一种方法,通过在脚本中结合使用 inotify 及 rsync实现数据实时同步. 1.安装 rsync: [[email protected] ~]# yum install -y openssh-clients rsync 这里要注意两点,一是进行同步的两台服务器上均需安装 rsync ,二是 rsync 需要依赖 openssh-cli

rsync + inotify 实时同步数据

简介 Rsync (remote sync)是一款开源.快速,多功能.可实现增量的本地或远程数据镜像同步备份优秀工具.它可通过 LAN/WAN 快速同步多台主机间的文件.rsync 当前由 rsync.samba.org 维护.rsync 使用所谓的"rsync演算法"来使本地和远程主机之间的文件达到同步,该算法只传送两个文件中的不同部分,而不是每次都整份传送,因此速度相当快. 特点:   1.可以镜像保存整个目录树或文件系统:   2.可实现增量同步,既只同步发生变化的数据,因此数据

”免“验证rsync-inotify同步数据

拓扑图: 实验中我先利用rsync在192.168.150.151下载192.168.150.150的源数据到本地,然后在192.168.150.150利用rsync和inotify实时同步数据到192.168.150.151. rsync [选项]源位置   目标位置 -r:递归模式,包含目录及子目录中的所有文件 -l:复制符号链接文件 -v:显示同步过程 -a:归档模式,保留文件的权限,属性等信息 -z:在传输过程中压缩 -p:保留权限标记 -t:保留文件的时间标记 -H:保留硬链接 -A:

linux和windows同步数据 cwrsync client to rsync server

linux和windows同步数据,rsync server  cwrsync client linux server一般系统都自带rsync,如果没有就挂载系统盘自己安装一下,安装挺简单的不用我再多说了vi /etc/rsyncd.confuid = daemon                            //这个用户是系统用户,当rsync客户端连接上服务器后,会映射成这个用户上传或者下载文件gid = daemon                            //组名