def retrieve_snapshots(self): """ Determine snapshot names. Snapshot names are sorted in reverse order (newest first). stored internally (self.snapshot_names) and also returned. """ self._log_info('retrieving snapshots') output = self.exec_check_output('btrfs sub list -o "%s"' % self.container_subvolume_path) # output is delivered as a byte sequence, decode to unicode string and split lines lines = output.decode().splitlines() subvolumes = list(map(lambda x: Subvolume.parse(x), lines)) # verify snapshot subvolume path consistency if len(subvolumes) > 0: subvol_path = os.path.dirname(subvolumes[0].path) subvol_inconsistent_path = \ next((s.path for s in subvolumes if os.path.dirname(s.path) != subvol_path), None) if subvol_inconsistent_path: raise Exception( 'inconsistent path detected at %s [%s != %s], indicating a nested' ' folder/subvolume structure within a container subvolume.' ' each backup job must have a dedicated source/destination container subvolume' % (self.url.path, subvol_path, subvol_inconsistent_path)) # sort and return snapshots = [] for sv in subvolumes: try: snapshots.append( Snapshot(SnapshotName.parse(os.path.basename(sv.path)), sv)) except: # skip snapshot names which cannot be parsed pass self.__snapshots = sorted(snapshots, key=lambda s: s.name.timestamp, reverse=True) return self.__snapshots
def retrieve_snapshots(self): """ Determine snapshot names. Snapshot names are sorted in reverse order (newest first). stored internally (self.snapshot_names) and also returned. """ self._log_info('retrieving snapshots') output = self.exec_check_output('btrfs sub list -o "%s"' % self.container_subvolume_path) # output is delivered as a byte sequence, decode to unicode string and split lines lines = output.decode().splitlines() subvolumes = list(map(lambda x: Subvolume.parse(x), lines)) # verify snapshot subvolume path consistency if len(subvolumes) > 0: subvol_path = os.path.dirname(subvolumes[0].path) subvol_inconsistent_path = \ next((s.path for s in subvolumes if os.path.dirname(s.path) != subvol_path), None) if subvol_inconsistent_path: raise Exception('inconsistent path detected at %s [%s != %s], indicating a nested' ' folder/subvolume structure within a container subvolume.' ' each backup job must have a dedicated source/destination container subvolume' % (self.url.path, subvol_path, subvol_inconsistent_path)) # sort and return snapshots = [] for sv in subvolumes: try: snapshots.append(Snapshot(SnapshotName.parse(os.path.basename(sv.path)), sv)) except: # skip snapshot names which cannot be parsed pass self.__snapshots = sorted(snapshots, key=lambda s: s.name.timestamp, reverse=True) return self.__snapshots
def test_instantiation(self): print(SnapshotName.parse('sx-20150102-132010-utc'))