|
|
@ -6,6 +6,8 @@ def main(): |
|
|
config = json.load(config_file) |
|
|
config = json.load(config_file) |
|
|
|
|
|
|
|
|
backup_path = config['local']['path'] |
|
|
backup_path = config['local']['path'] |
|
|
|
|
|
backup_server_age = config['local']['backup_server_age'] |
|
|
|
|
|
backup_local_age = config['local']['backup_age'] |
|
|
|
|
|
|
|
|
hosts = config['remote'] |
|
|
hosts = config['remote'] |
|
|
|
|
|
|
|
|
@ -15,13 +17,21 @@ def main(): |
|
|
backup_dir = '{}/{}'.format(backup_path, service).lower() |
|
|
backup_dir = '{}/{}'.format(backup_path, service).lower() |
|
|
if not os.path.exists(backup_dir): |
|
|
if not os.path.exists(backup_dir): |
|
|
os.mkdir(backup_dir) |
|
|
os.mkdir(backup_dir) |
|
|
|
|
|
print('deleting local files older than {}days in {}'.format( |
|
|
|
|
|
backup_local_age, backup_dir |
|
|
|
|
|
)) |
|
|
|
|
|
cmd = 'find {} -mindepth 1 -mtime +{} -delete'.format( |
|
|
|
|
|
backup_dir, backup_local_age |
|
|
|
|
|
) |
|
|
|
|
|
print('({})'.format(cmd)) |
|
|
|
|
|
os.system(cmd) |
|
|
print('from ' + hosts[host][service] + ' to ' + backup_dir) |
|
|
print('from ' + hosts[host][service] + ' to ' + backup_dir) |
|
|
cmd = 'scp {}:{}/* {}'.format(host, hosts[host][service], |
|
|
cmd = 'scp {}:{}/* {}'.format(host, hosts[host][service], |
|
|
backup_dir) |
|
|
backup_dir) |
|
|
print('({})'.format(cmd)) |
|
|
print('({})'.format(cmd)) |
|
|
os.system(cmd) |
|
|
os.system(cmd) |
|
|
cmd = 'ssh {} rm -f {}/* '.format(host, hosts[host][service], |
|
|
|
|
|
backup_dir) |
|
|
|
|
|
|
|
|
cmd = 'ssh {} "find {} -mindepth 1 -mtime +{} -delete"'.format( |
|
|
|
|
|
host, hosts[host][service],backup_dir, backup_server_age) |
|
|
print('({})'.format(cmd)) |
|
|
print('({})'.format(cmd)) |
|
|
os.system(cmd) |
|
|
os.system(cmd) |
|
|
|
|
|
|
|
|
|