diff options
author | Lars Wirzenius <liw@liw.fi> | 2016-08-12 19:21:02 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2016-08-12 19:21:02 +0300 |
commit | ab5e116e6dc5689ab3020951d5e5c84ceadc11f7 (patch) | |
tree | bb22d47ec54dc2d0bbcb883f928e0bac57c76711 | |
parent | a909a2a757f3d5d39f4bd00a803323a9b7f1e336 (diff) | |
download | obnam-ab5e116e6dc5689ab3020951d5e5c84ceadc11f7.tar.gz |
Make --one-file-system work for bind mounts
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | obnamlib/plugins/one_file_system_plugin.py | 16 |
2 files changed, 20 insertions, 1 deletions
@@ -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 |