MySQL imports several data to the line every few hours

Source: Internet
Author: User

1 as a company needs to, the offline database needs to guide several data to the online database every few hours2  3[[email protected] BBS]#Rpm-qa | grep "expect"4Expect-5.44.1.15-5. el6_4.x86_645If there is no Yum-y Install expect6  71, SSH mapping8 ssh_bbs.sh9 #!/usr/bin/expectTenSet Timeout 20 OneSpawn ssh-c-f-n-g-i ID_DSA (key)-L native ip:20222 (port mapped to native): Offline intranet dbhosts:3306 [email protected] Extranet IP-P22 AExpect"*passphrase*" -Send"wdzjdsakey\r" -Expect"Suspend" the   -2, ps_ssh.sh -Ps-ef | Grep"192.168.11.45:20222"| grep-v grep - if[ $? !=0] +  Then -./ssh_bbs.sh + fi A   at3,mysql_export.py - #!/usr/bin/python - ImportMySQLdb - Import Time - ImportCommands,sys - Importsubprocess in  -Times=time.strftime ('%y-%m-%d-%h:%m:%s') to  + defcmd (mysql_cmd): -(status,output) =commands.getstatusoutput (mysql_cmd) the      ifStatus = =0: *           PrintMysql_cmd+'... is ok' $      elifStatus = = 256:Panax Notoginseng           Print 'Yes' -           PrintMysql_cmd+'... is ok' the      Else: +Sys.exit (1) A  theConn=mysqldb.connect ('192.168.11.23','Root','Root','Test', charset='UTF8') +Cur=conn.cursor () -Cur.execute ("Select ID from wenda_question ORDER by id DESC") $ #Cur.execute ("SELECT ID from wenda_question") $mem=0 -  forIinchCur.fetchall (): -Mem+=1 the      ifMem>20: -mem=0WuyiTime.sleep (3600) thecmd"kill-9 ' ps-ef | grep ' 192.168.11.45:20222 ' | grep-v Grep|awk ' {print $} ' |xargs '") -Time.sleep (30) WuSubprocess. Popen ("SH ps_ssh.sh", subprocess. Pipe,shell =True) -Time.sleep (20) Aboutcmd'ps-ef | grep "192.168.11.45:20222" | grep-v grep') $           Print Times -question='mysqldump-uroot-proot-h192.168.11.23--skip-add-drop-table Test wenda_question-w "id='+str (I[0]) +'">wenda_question.sql' -Answer='mysqldump-uroot-proot-h192.168.11.23--skip-add-drop-table Test wenda_answer-w "qid='+str (I[0]) +'">wenda_answer.sql' -question_import='mysql-uwdzj-pwdzj_2014_bbsnew-h192.168.11.45-p 20222-f Wdzj_wenda < Wenda_answer.sql' Aanswer_import='mysql-uwdzj-pwdzj_2014_bbsnew-h192.168.11.45-p 20222-f Wdzj_wenda < Wenda_question.sql' + cmd (question) the cmd (answer) - cmd (question_import) $CMD (answer_import)

MySQL imports several data to the line every few hours

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.