Browse Source

rewrite backuo script

master
Christian Urich 5 years ago
parent
commit
9e2323083f
2 changed files with 12 additions and 20 deletions
  1. +12
    -19
      backup.py
  2. +0
    -1
      requirements.txt

+ 12
- 19
backup.py View File

@ -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__':


+ 0
- 1
requirements.txt View File

@ -1 +0,0 @@
fabric

Loading…
Cancel
Save