the tool to backup stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

43 lines
1.5 KiB

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 {} -mindepth 1 -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 {} -mindepth 1 -mtime +{} -delete"'.format(
host, hosts[host][service],backup_dir, backup_server_age)
print('({})'.format(cmd))
os.system(cmd)
if __name__ == '__main__':
main()