import json
|
|
import os
|
|
|
|
def main():
|
|
backup_path = '/Users/Jowe1999/Desktop/test'
|
|
with open('config.json', 'r') as config_file:
|
|
config = json.load(config_file)
|
|
|
|
for host in config:
|
|
print('conect to ' + host)
|
|
for service in config[host]:
|
|
backup_dir = '{}/{}'.format(backup_path, service).lower()
|
|
if not os.path.exists(backup_dir):
|
|
os.mkdir(backup_dir)
|
|
print('from ' + config[host][service] + ' to ' + backup_dir)
|
|
cmd = 'scp {}:{}/* {}'.format(host, config[host][service],
|
|
backup_dir)
|
|
print('({})'.format(cmd))
|
|
os.system(cmd)
|
|
cmd = 'ssh {} rm -f {}/* '.format(host, config[host][service],
|
|
backup_dir)
|
|
print('({})'.format(cmd))
|
|
os.system(cmd)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|
|
|
|
|