本文实例为大家分享了python rsync服务器之间文件夹同步的具体代码,供大家参考,具体内容如下
配置两台服务器之间3ssh-key后,可以实现自动化无需手动输入密码,脚本如下:
import argparse
import datetime
from functools import partial
import multiprocessing as mp
import os
import paramiko as pmk
import time
def check_ssh(host, user, port, passwd, dest_path):
ssh_client = pmk.SSHClient()
ssh_client.load_system_host_keys()
ssh_client.set_missing_host_key_policy(pmk.AutoAddPolicy())
try:
ssh_client.connect(host, username=user, port=port, timeout=10, password=passwd)
ssh_client.exec_command('mkdir ' + os.path.join(dest_path, 'data'))
except BaseException as e:
print 'failed to connect to host: %r: %r' % (host, e)
return False
else:
return True
def select_from_file(fil