import json
|
|
import os
|
|
|
|
def main():
|
|
with open('config.json', 'r') as config_file:
|
|
config = json.load(config_file)
|
|
|
|
backup_path = config['local']['path']
|
|
backup_server_age = config['local']['backup_server_age']
|
|
backup_local_age = config['local']['backup_age']
|
|
|
|
hosts = config['remote']
|
|
|
|
for host in hosts:
|
|
print('conect to ' + host)
|
|
for service in hosts[host]:
|
|
backup_dir = '{}/{}'.format(backup_path, service).lower()
|
|
if not os.path.exists(backup_dir):
|
|
os.mkdir(backup_dir)
|
|
print('deleting local files older than {}days in {}'.format(
|
|
backup_local_age, backup_dir
|
|
))
|
|
cmd = 'find {} -type f -mtime +{} -delete'.format(
|
|
backup_dir, backup_local_age
|
|
)
|
|
print('({})'.format(cmd))
|
|
os.system(cmd)
|
|
print('from ' + hosts[host][service] + ' to ' + backup_dir)
|
|
cmd = 'scp {}:{}/* {}'.format(host, hosts[host][service],
|
|
backup_dir)
|
|
print('({})'.format(cmd))
|
|
os.system(cmd)
|
|
cmd = 'ssh {} "find {} -type f -mtime +{} -delete"'.format(
|
|
host, hosts[host][service], backup_server_age)
|
|
print('({})'.format(cmd))
|
|
os.system(cmd)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|
|
|
|
|