From ab5e116e6dc5689ab3020951d5e5c84ceadc11f7 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 12 Aug 2016 19:21:02 +0300 Subject: Make --one-file-system work for bind mounts --- NEWS | 5 +++++ obnamlib/plugins/one_file_system_plugin.py | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index bec96a03..31154454 100644 --- a/NEWS +++ b/NEWS @@ -39,6 +39,11 @@ Minor changes: * Lars Wirzenius added a chapter on participating in the Obnam project to the manual. +* Lars Wirzenius changed `--one-file-system` to work for bind mounts. + It only works for bind mounts that exist at the time when Obnam + starts, however. Also, `/proc/mounts` must be an accurate list of + mount points. + Bug fixes: * The manual and manual page used to claim you could break only the diff --git a/obnamlib/plugins/one_file_system_plugin.py b/obnamlib/plugins/one_file_system_plugin.py index 94101b8d..7b584c88 100644 --- a/obnamlib/plugins/one_file_system_plugin.py +++ b/obnamlib/plugins/one_file_system_plugin.py @@ -34,14 +34,28 @@ class OneFileSystemPlugin(obnamlib.ObnamPlugin): def config_loaded(self): if self.app.settings['one-file-system']: + self.load_mount_points() self.app.hooks.add_callback('backup-exclude', self.exclude) + def load_mount_points(self): + try: + with open('/proc/mounts', 'r') as f: + self.mount_points = self.parse_proc_mounts(f) + except EnvironmentError: + pass + + def parse_proc_mounts(self, f): + return [ + line.split()[1] + for line in f + ] + def exclude(self, **kwargs): st = kwargs['stat_result'] root_metadata = kwargs['root_metadata'] pathname = kwargs['pathname'] exclude = kwargs['exclude'] - if st.st_dev != root_metadata.st_dev: + if st.st_dev != root_metadata.st_dev or pathname in self.mount_points: logging.debug('Excluding (one-file-system): %s', pathname) exclude[0] = True -- cgit v1.2.1