From f76c91e5492093611528c35f553ecb4c0c0b6cc2 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sun, 14 Apr 2019 21:22:11 +0200 Subject: [PATCH] Filter mounts based on include/exclude patterns --- restic-backup/containers.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/restic-backup/containers.py b/restic-backup/containers.py index 25c92d0..f5844c9 100644 --- a/restic-backup/containers.py +++ b/restic-backup/containers.py @@ -39,13 +39,31 @@ class Container: def is_oneoff(self): return self.labels['com.docker.compose.oneoff'] == 'True' + def filter_mounts(self): + """Get all mounts for this container matching filters""" + for mount in self.mounts: + if self.include: + for pattern in self.include: + if pattern in mount.source: + yield mount + continue + elif self.exlude: + for pattern in self.exlude: + if pattern in mount.source: + continue + yield mount + else: + yield mount + def to_dict(self): return { 'Id': self.id, 'Names': self.names, 'State': self.state, 'Labels': self.labels, - 'Mounts': [mnt.data for mnt in self.mounts] + 'Mounts': [mnt.data for mnt in self.mounts], + 'include': self.include, + 'exclude': self.exlude, } @@ -137,10 +155,6 @@ class RunningContainers: self.containers.append(container) - - def backup_volumes(self): - return self.backup_container.mounts - def gen_volumes(self, volume_type): """Generator yielding volumes of a specific type""" for cont in self.containers: