Browse Source

add featur to delete old local and server backups

add configuration to dellet old backups on server and local after they
are older than a certain amount of time
master
Christian Urich 5 years ago
parent
commit
022c4224fb
2 changed files with 15 additions and 3 deletions
  1. +12
    -2
      backup.py
  2. +3
    -1
      config.json.example

+ 12
- 2
backup.py View File

@ -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)


+ 3
- 1
config.json.example View File

@ -9,6 +9,8 @@
} }
}, },
"local" : { "local" : {
"path" : "/backup/storage/folder/"
"path" : "/backup/storage/folder/",
"backup_server_age" : 7,
"backup_age" : 30
} }
} }

Loading…
Cancel
Save