diff --git a/backup.py b/backup.py index 0e2927f..fbba00d 100644 --- a/backup.py +++ b/backup.py @@ -1,33 +1,26 @@ -from fabric import Connection, Config, Result import json import os def main(): - backup_path = '/mnt/sda/backups' + backup_path = '/Users/Jowe1999/Desktop/test' with open('config.json', 'r') as config_file: config = json.load(config_file) - print(config) for host in config: print('conect to ' + host) - conn = Connection(host=host, port=22) for service in config[host]: backup_dir = '{}/{}'.format(backup_path, service).lower() - print('from' + config[host][service] + ' to ' + backup_dir) - conn.get(config[host][service], backup_dir.lower()) - conn.run('rm {}'.format(config[host][service])) - - - #for server in config: - # print('conect to ' + server) - # #conn = Connection(host=server, port=22) - # for service in server: - # backup_dir = '{}/{}'.format(backup_path, service) - # print('to ' + backup_dir) - # #if not os.path.exists(backup_dir): - # #os.mkdir(backup_dir) - # #conn.get(config[server][service], backup_dir) - # #conn.run('rm config[server][service]') + 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__': diff --git a/requirements.txt b/requirements.txt index 16f07d4..e69de29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +0,0 @@ -fabric \ No newline at end of file