使用paramikoHelper类实现MySQL安装和数据恢复
时间:2021-07-01 10:21:17
帮助过:2人阅读
paramikoHelper
import os
sshObj = paramikoHelper.myParamiko(ip,
‘root‘,
‘xxxxxxxx‘)
filepath =
‘/opt/packages/mysql‘
#指定rpm包的目录,通过yum -y install mysql mysql-server --downloadonly --downloaddir=./ 下载下来
filelist =
os.walk(filepath)
filenameList =
[]
for path,dir,files
in filelist:
for file
in files:
sshObj.put(os.path.join(path,file),‘/root/‘ +
file)
filenameList.append(file)
cmdlist =
[]
cmdlist.append(‘rpm -i perl-DBI-1.609-4.el6.x86_64.rpm‘)
cmdlist.append(‘rpm -i mysql-libs-5.1.73-7.el6.x86_64.rpm‘)
cmdlist.append(‘rpm -i perl-DBD-MySQL-4.013-3.el6.x86_64.rpm‘)
cmdlist.append(‘rpm -i mysql-5.1.73-7.el6.x86_64.rpm‘)
cmdlist.append(‘rpm -i mysql-server-5.1.73-7.el6.x86_64.rpm‘)
cmdlist.append(‘service mysqld start‘)
cmdlist.append(‘mysql < /root/all.sql‘)
cmdlist.append(‘service mysqld restart‘)
cmdlist.append(‘chkconfig mysqld on‘)
sshObj.run_cmdlist(cmdlist)
cmdlist =
[]
for name
in filenameList:
cmdlist.append(‘rm -rf /root/‘ +
name)
sshObj.run_cmdlist(cmdlist)
sshObj.close()
使用paramikoHelper类实现MySQL安装和数据恢复
标签: