def verify_metadata(self, gen_id, filename): try: live_data = obnamlib.read_metadata(self.fs, filename) except OSError, e: raise Fail( filename=filename, reason='missing or inaccessible: %s' % e.strerror)
def find_files(self, root): '''Find all files and directories that need to be backed up. This is a generator. It yields (pathname, metadata) pairs. The caller should not recurse through directories, just backup the directory itself (name, metadata, file list). ''' for pathname, st in self.fs.scan_tree(root, ok=self.can_be_backed_up): tracing.trace('considering %s' % pathname) try: metadata = obnamlib.read_metadata(self.fs, pathname, st=st) self.progress.update_progress_with_file(pathname, metadata) if self.needs_backup(pathname, metadata): self.progress.backed_up_count += 1 yield pathname, metadata else: self.progress.update_progress_with_scanned( metadata.st_size) except GeneratorExit: raise except KeyboardInterrupt: logging.error('Keyboard interrupt') raise except BaseException, e: msg = 'Cannot back up %s: %s' % (pathname, str(e)) self.error(msg, e)
def find_files(self, root): '''Find all files and directories that need to be backed up. This is a generator. It yields (pathname, metadata) pairs. The caller should not recurse through directories, just backup the directory itself (name, metadata, file list). ''' for pathname, st in self.fs.scan_tree(root, ok=self.can_be_backed_up): tracing.trace('considering %s' % pathname) try: metadata = obnamlib.read_metadata(self.fs, pathname, st=st) self.progress.update_progress_with_file(pathname, metadata) if self.needs_backup(pathname, metadata): yield pathname, metadata else: self.progress.update_progress_with_scanned( metadata.st_size) except GeneratorExit: raise except KeyboardInterrupt: logging.error('Keyboard interrupt') raise except BaseException, e: msg = 'Cannot back up %s: %s' % (pathname, str(e)) self.progress.error(msg, e)
def verify_metadata(self, gen_id, filename): try: live_data = obnamlib.read_metadata(self.fs, './' + filename) except OSError, e: raise Fail( filename=filename, reason='missing or inaccessible: %s' % e.strerror)
def test_returns_symlink_fields_correctly(self): self.fakefs.st_mode |= stat.S_IFLNK metadata = obnamlib.read_metadata( self.fakefs, "foo", getpwuid=self.fakefs.getpwuid, getgrgid=self.fakefs.getgrgid ) fields = ["st_mode", "target"] for field in fields: self.assertEqual(getattr(metadata, field), getattr(self.fakefs, field), field)
def test_returns_symlink_fields_correctly(self): self.fakefs.st_mode |= stat.S_IFLNK metadata = obnamlib.read_metadata(self.fakefs, 'foo', getpwuid=self.fakefs.getpwuid, getgrgid=self.fakefs.getgrgid) fields = ['st_mode', 'target'] for field in fields: self.assertEqual(getattr(metadata, field), getattr(self.fakefs, field), field)
def test_returns_stat_fields_correctly(self): metadata = obnamlib.read_metadata(self.fakefs, 'foo', getpwuid=self.fakefs.getpwuid, getgrgid=self.fakefs.getgrgid) fields = ['st_atime_sec', 'st_atime_nsec', 'st_blocks', 'st_dev', 'st_gid', 'st_ino', 'st_mode', 'st_mtime_sec', 'st_mtime_nsec', 'st_nlink', 'st_size', 'st_uid', 'groupname', 'username'] for field in fields: self.assertEqual(getattr(metadata, field), getattr(self.fakefs, field), field)
def test_returns_stat_fields_correctly(self): metadata = obnamlib.read_metadata(self.fakefs, 'foo', getpwuid=self.fakefs.getpwuid, getgrgid=self.fakefs.getgrgid) fields = [ 'st_atime_sec', 'st_atime_nsec', 'st_blocks', 'st_dev', 'st_gid', 'st_ino', 'st_mode', 'st_mtime_sec', 'st_mtime_nsec', 'st_nlink', 'st_size', 'st_uid', 'groupname', 'username' ] for field in fields: self.assertEqual(getattr(metadata, field), getattr(self.fakefs, field), field)
def backup_parents(self, root): '''Back up parents of root, non-recursively.''' root = self.fs.abspath(root) tracing.trace('backing up parents of %s', root) dummy_metadata = obnamlib.Metadata(st_mode=0777 | stat.S_IFDIR) while True: parent = os.path.dirname(root) try: metadata = obnamlib.read_metadata(self.fs, root) except OSError, e: logging.warning( 'Failed to get metadata for %s: %s: %s' % (root, e.errno or 0, e.strerror)) logging.warning('Using fake metadata instead for %s' % root) metadata = dummy_metadata if not self.pretend: self.repo.create(root, metadata) if root == parent: break root = parent
def test_returns_stat_fields_correctly(self): metadata = obnamlib.read_metadata( self.fakefs, "foo", getpwuid=self.fakefs.getpwuid, getgrgid=self.fakefs.getgrgid ) fields = [ "st_atime_sec", "st_atime_nsec", "st_blocks", "st_dev", "st_gid", "st_ino", "st_mode", "st_mtime_sec", "st_mtime_nsec", "st_nlink", "st_size", "st_uid", "groupname", "username", ] for field in fields: self.assertEqual(getattr(metadata, field), getattr(self.fakefs, field), field)
def backup_parents(self, root): '''Back up parents of root, non-recursively.''' root = self.fs.abspath(root) tracing.trace('backing up parents of %s', root) dummy_metadata = obnamlib.Metadata(st_mode=0777 | stat.S_IFDIR) while True: parent = os.path.dirname(root) try: metadata = obnamlib.read_metadata(self.fs, root) except OSError, e: logging.warning('Failed to get metadata for %s: %s: %s' % (root, e.errno or 0, e.strerror)) logging.warning('Using fake metadata instead for %s' % root) metadata = dummy_metadata if not self.pretend: self.add_file_to_generation(root, metadata) if root == parent: break root = parent
def test_reads_username_as_None_if_lookup_fails(self): metadata = obnamlib.read_metadata(self.fakefs, 'foo', getpwuid=self.fakefs.fail_getpwuid, getgrgid=self.fakefs.fail_getgrgid) self.assertEqual(metadata.username, None)
def test_reads_username_as_None_if_lookup_fails(self): metadata = obnamlib.read_metadata(self.fakefs, 'foo', getpwuid=self.fakefs.fail_getpwuid, getgrgid=self.fakefs.fail_getgrgid) self.assertEqual(metadata.username, None)
def verify_metadata(self, gen, filename, backed_up): try: live_data = obnamlib.read_metadata(self.fs, filename) except OSError, e: raise Fail(filename, 'missing or inaccessible: %s' % e.strerror)