首页 > 代码库 > 使用paramikoHelper类实现MySQL安装和数据恢复

使用paramikoHelper类实现MySQL安装和数据恢复

本脚本实现远程Linux主机登陆和安装MySQL的rpm包,同时导入mysql数据,实现自动化安装

paramikoHelper类在本博客中 http://www.cnblogs.com/djoker/p/5906711.html

脚本内容:

import paramikoHelperimport ossshObj = 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安装和数据恢复