MySQL 設置裝備擺設文件my.cnf 例子最具體翻譯。本站提示廣大學習愛好者:(MySQL 設置裝備擺設文件my.cnf 例子最具體翻譯)文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL 設置裝備擺設文件my.cnf 例子最具體翻譯正文
情況:【wind2003[open Tftp server] + virtualbox:ubuntn10 server】
tftp : Open TFTP Server
ubuntn
python + pyexpect
采取虛擬機緣由: pyexpect 不支撐windows
注:原盤算采取secrueCrt 劇本編寫,因理論中發明沒有應用linux下pexpect易用,靈巧 ,之前習氣應用expect,因tcl【語法】沒有python易用、易保護
編寫些法式緣由:
比來出了比擬嚴重毛病:因netscreen裝備bug,一個節點主備裝備同時出毛病,改換裝備後,發明備份設置裝備擺設文件湧現亂碼【中文】,不克不及直接應用。
斟酌裝備在內網,今朝有近300台數通裝備,是以采取原始tftp備份方法
因備份裝備不多:暫只斟酌功效,法式效力放在主要
宣布:
根本完成netscreen,cisco ios, hw vrp,h3c f1000裝備 備份法式
分別出裝備信息設置裝備擺設 2.增長備份能否勝利檢測
成績:
1 未處理ping 弗成達重要,反應慢成績 處理方法:ip 一項,不支撐主機名,在 ipCheck函數中添加檢討地址停止處理
2.登錄裝備安排expect代碼,沒有處置認證掉敗情形,或許超時等根本檢討成績
#coding:utf-8
#!/usr/bin/python
'''
program: run.py
'''
import pexpect
import datetime
import time
import os
import re
#tftp辦事器
tftpServer='192.168.1.115'
#備份主機列表【設置裝備擺設格局以下】
#ip 備份劇本[體系類型] 登錄帳號 暗碼 super暗碼 能否須要備份
backupHosts=[
{"ip":"192.168.1.27","script":"vrp","login":"test","passwd":"*****","su_passwd":"*****","check":"Y"},
{"ip":"192.168.1.28","script":"vrp","login":"test","passwd":"*****","su_passwd":"*****","check":"Y"},
{"ip":"192.10.100.100","script":"vrp","login":"test","passwd":"*****","su_passwd":"*****","check":"Y"},
{"ip":"192.10.100.101","script":"vrp","login":"test","passwd":"*****","su_passwd":"*****","check":"Y"},
{"ip":"192.10.98.167","script":"juniper","login":"netscreen","passwd":"*****","su_passwd":"*****","check":"Y"},
{"ip":"192.10.98.168","script":"juniper","login":"netscreen","passwd":"*****","su_passwd":"*****","check":"Y"},
{"ip":"192.168.1.124","script":"h3c_firewall","login":"test","passwd":"*****","su_passwd":"*****","check":"Y"},
{"ip":"192.168.1.125","script":"h3c_firewall","login":"test","passwd":"*****","su_passwd":"*****","check":"Y"},
{"ip":"192.10.98.233","script":"ios","login":"test","passwd":"*****","su_passwd":"*****","check":"Y"},
{"ip":"192.10.98sd","script":"ios","login":"test","passwd":"*****","su_passwd":"*****","check":"Y"},
]
# 檢討主機能否可達
def ipCheck(ip):
if re.match(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",ip):
if os.uname()[0] == "Linux":
output=os.popen("/bin/ping -c 1 -W 2 %s" % (ip)).read().split("\n")
if "1 packets transmitted, 1 received, 0% packet loss, time 0ms" in output:
return True
else:
return False
else:
return False
# 發生日期
def getToday():
return datetime.date.today()
'''焦點代碼'''
def telnet_hw3552(ip,login,passwd,su_passwd):
try:
foo = pexpect.spawn('/usr/bin/telnet %s' % (ip))
index = foo.expect(['sername:', 'assword:'])
if index == 0:
foo.sendline(login)
foo.expect("assword:")
foo.sendline(passwd)
elif index == 1:
foo.sendline(passwd)
foo.expect(">")
foo.sendline("super")
foo.expect("assword:")
foo.sendline(su_passwd)
foo.expect(">")
foo.sendline("tftp %s put %s %s " % (tftpServer,"vrpcfg.cfg",ip+"_hw_"+str(getToday())+".cfg"))
index=foo.expect(["successfully","Error"])
if index == 1:
foo.sendline(" ")
foo.expect(">")
foo.sendline("tftp %s put %s %s " % (tftpServer,"vrpcfg.zip",ip+"_hw_"+str(getToday())+".zip"))
foo.sendline("quit")
except pexpect.EOF:
foo.close()
else:
foo.close
#思科ios體系交流機
def telnet_ciscoios(ip,login,passwd,su_passwd):
try:
foo = pexpect.spawn('/usr/bin/telnet %s' % (ip))
index = foo.expect(['sername:', 'assword:'])
if index == 0:
foo.sendline(login)
foo.expect("assword:")
foo.sendline(passwd)
elif index == 1:
foo.sendline(passwd)
foo.expect(">")
foo.sendline("en")
foo.expect("assword:")
foo.sendline(su_passwd)
foo.expect("#")
foo.sendline("copy running-config tftp")
foo.expect(".*remote.*")
foo.sendline("%s" % (tftpServer))
foo.expect(".*filename.*")
foo.sendline("%s" % (ip+"_ciscoIos_"+str(getToday())+"_runningconfig.cfg"))
foo.expect("#")
foo.sendline("exit")
except pexpect.EOF:
foo.close()
else:
foo.close
#h3c防火牆
def telnet_h3cfirewallf1000(ip,login,passwd,su_passwd):
try:
foo = pexpect.spawn('/usr/bin/telnet %s' % (ip))
index = foo.expect(['sername:', 'assword:'])
if index == 0:
foo.sendline(login)
foo.expect("assword:")
foo.sendline(passwd)
elif index == 1:
foo.sendline(passwd)
foo.expect(">")
foo.sendline("tftp %s put %s %s " % (tftpServer,"startup.cfg",ip+"_h3cf1000_"+str(getToday())+"_startup.cfg"))
foo.expect(">")
foo.sendline("tftp %s put %s %s " % (tftpServer,"system.xml",ip+"_h3cf1000_"+str(getToday())+"_system.xml"))
foo.expect(">")
foo.sendline("quit")
except pexpect.EOF:
foo.close()
else:
foo.close
#netscreen firewall
def telnet_netscren(ip,login,passwd,su_passwd):
try:
foo = pexpect.spawn('/usr/bin/telnet %s' % (ip))
index = foo.expect(['login:', 'assword:'])
if index == 0:
foo.sendline(login)
foo.expect("assword:")
foo.sendline(passwd)
elif index == 1:
foo.sendline(passwd)
foo.expect(">")
foo.sendline(su_passwd)
foo.expect(">")
foo.sendline("save config to tftp %s %s" % (tftpServer,ip+"_netscreen_"+str(getToday())+".cfg"))
foo.expect("Succeeded")
foo.expect(">")
foo.sendline("exit")
foo.expect(".*save.*")
foo.sendline("Y")
except pexpect.EOF:
foo.close()
else:
foo.close
#挪用焦點代碼函數
def run():
'''先檢查設置裝備擺設,確認裝備能否須要備份, 再確認裝備能否收集可達,ok才停止備份操作'''
for i in backupHosts:
if i['check'] == "Y":
if ipCheck(i['ip']):
print(" --->>> backup %s ......" % (i['ip']))
if i['script'] == "vrp":
telnet_hw3552(i['ip'],i['login'],i['passwd'],i['su_passwd']) #cfg
elif i['script'] == "ios":
telnet_ciscoios(i['ip'],i['login'],i['passwd'],i['su_passwd']) #cisco
elif i['script'] == "juniper":
telnet_netscren(i['ip'],i['login'],i['passwd'],i['su_passwd']) #juniper netscreen
elif i['script'] == "h3c_firewall":
telnet_h3cfirewallf1000(i['ip'],i['login'],i['passwd'],i['su_passwd']) # h3c firewall
else:
print("%s [%s] nonsupoort this type system host" % (i['ip'],i['script']))
else:
print("unknown host %s or hosts ip config error" % (i['ip']))
#+++++++++++++++++++++main+++++++++++++++++++=
if __name__ == "__main__":
#履行備份
run()
#檢討備份能否勝利
print("----------------------- report ------------------")
backupPath='/win_data/tftp_log' #備份途徑
tftpList=[]
for i in os.popen("ls %s | grep \"%s\"" % (backupPath,getToday())).readlines(): #將備份到文件寄存於列表中
tftpList.append(i.split("_")[0])
for i in backupHosts: #檢討須要備份裝備,能否備份到[tftp上有無文件] 沒:則提醒
if i['check'] == "Y":
if i['ip'] not in tftpList:
print("%s backup error" % (i['ip']))
'''
#測試
testistrator@python:/win_data$ python run.py
--->>> backup 192.168.1.27 ......
--->>> backup 192.168.1.28 ......
--->>> backup 192.10.100.100 ......
--->>> backup 192.10.100.101 ......
--->>> backup 192.10.98.167 ......
--->>> backup 192.10.98.168 ......
--->>> backup 192.168.1.124 ......
--->>> backup 192.168.1.125 ......
--->>> backup 192.10.98.233 ......
unknown host 192.10.98sd or hosts ip config error
----------------------- report ------------------
192.10.98sd backup error
'''