From 3b284f68ca4d1b081ec3c5e5a21dae1fca8d7925 Mon Sep 17 00:00:00 2001 From: Christian Urich Date: Fri, 2 Apr 2021 22:51:59 +0200 Subject: [PATCH] easy script to download and manage backups --- backup.py | 24 ++++++++++++++++++++++++ config.json | 0 config.json.example | 9 +++++++++ 3 files changed, 33 insertions(+) create mode 100644 backup.py create mode 100644 config.json create mode 100644 config.json.example diff --git a/backup.py b/backup.py new file mode 100644 index 0000000..5c53f76 --- /dev/null +++ b/backup.py @@ -0,0 +1,24 @@ +from fabric import Connection, Config, Result +import json +import os + +def main(): + backup_path = '/mnt/sda/backups' + with open('config.json', 'r') as config_file: + config = json.load(config_file) + + for server in config.keys: + conn = Connection(host=server, port=22) + for service in config[server].keys: + backup_dir = '{}/{}'.format(backup_path, service) + 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 __name__ == '__main__': + main() + + + diff --git a/config.json b/config.json new file mode 100644 index 0000000..e69de29 diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..9f8c930 --- /dev/null +++ b/config.json.example @@ -0,0 +1,9 @@ +{ + "host" : { + "service" : "path/to/backups/*" + }, + "host2" : { + "service1" : "path/to/backups/*", + "service2" : "path/to/backups/*" + } +} \ No newline at end of file