+ def prune_snapshots(self):
+ if self.keep == -1:
+ print("No keep specified for %s, keeping all"%self.name)
+ return
+
+ snaps = sorted([snap for snap in os.listdir(self.host_dir) if not snap == "latest" ], reverse=True)
+ while len(snaps) > self.keep:
+ snap = snaps.pop()
+ try:
+ check_call(shlex.split("btrfs subvol delete %s"%(os.path.join(self.host_dir, snap))))
+ except CalledProcessError as ex:
+ pass
+
+class BackupRunner():
+ def __init__(self, config_dir, dest_dir):
+ self.config_dir = config_dir
+ self.dest_dir = dest_dir
+ if not os.path.exists(self.config_dir):
+ print("No config found", self.config_dir)
+ sys-exit(-1)
+
+ def run(self):
+ self.hosts = os.listdir(self.config_dir)
+
+ for host in self.hosts:
+ if host == 'default.cfg':
+ continue
+ try:
+ config = configparser.ConfigParser(strict=False)
+ config.read_file(open(os.path.join(self.config_dir, 'default.cfg'),'r'))
+ config.read(os.path.join(self.config_dir, host))
+ except BaseException as ex:
+ print("Config error for %s. Skipping host."%host)
+ continue
+ h = Host(host, config)
+ h.prune_snapshots()
+ h.backup()
+