Example #1
0
 def _create_working_snapshot(self):
     self._ensure_subvolume()
     if os.path.exists(self.working_dir):
         print("Warning: working dir existed, are you sure no rsync job is running?")
     else:
         # print("btrfs subvolume snapshot {} {}".format(self.service_dir, self.working_dir))
         sh.btrfs("subvolume", "snapshot", self.service_dir, self.working_dir)
Example #2
0
def expand_filesystem(partition):
    with partition.losetup_context_manager() as device:
        # Detects the partition filesystem (ext{2,3,4} or btrfs) and uses the
        # appropriate tool to expand the filesystem to all the available space.
        fs = get_filesystem(device)
        log.info("Resizing {} filesystem of {} using {}".format(
            fs,
            partition.str(),
            device,
        ))
        if fs.startswith("ext"):
            try:
                kwargs = {"_ok_code": [0, 1, 2], **SH_OPTS}
                status = fsck("-p", "-f", device, **kwargs)
                if status.exit_code == 0:
                    log.info("File system OK")
                else:
                    log.warning("File system errors corrected")
            except ErrorReturnCode:
                raise Exception("File system errors could not be corrected")
            resize2fs("-f", device, **SH_OPTS)
        elif fs == "btrfs":
            # For btrfs we need to mount the fs for resizing.
            with mount_context_manager(device) as mountpoint:
                btrfs("filesystem", "resize", "max", mountpoint, **SH_OPTS)
Example #3
0
 def _create_working_snapshot(self):
     self._ensure_subvolume()
     if os.path.exists(self.working_dir):
         print(
             "Warning: working dir existed, are you sure no rsync job is running?"
         )
     else:
         # print("btrfs subvolume snapshot {} {}".format(self.service_dir, self.working_dir))
         sh.btrfs("subvolume", "snapshot", self.service_dir,
                  self.working_dir)
Example #4
0
    def walk(_dir, level=1):
        if level > args.max_level:
            return

        for fname in os.listdir(_dir):
            abs_fname = os.path.join(_dir, fname)
            if os.path.isdir(abs_fname):
                if pattern.match(fname):
                    print("GC: {}".format(abs_fname))
                    try:
                        sh.btrfs("subvolume", "delete", abs_fname)
                    except sh.ErrorReturnCode, e:
                        print("Error: {}".format(e.stderr))
                else:
                    walk(abs_fname, level + 1)
    def walk(_dir, level=1):
        if level > args.max_level:
            return

        for fname in os.listdir(_dir):
            abs_fname = os.path.join(_dir, fname)
            if os.path.isdir(abs_fname):
                if pattern.match(fname):
                    print("GC: {}".format(abs_fname))
                    try:
                        sh.btrfs("subvolume", "delete", abs_fname)
                    except sh.ErrorReturnCode, e:
                        print("Error: {}".format(e.stderr))
                else:
                    walk(abs_fname, level+1)
Example #6
0
 def _ensure_subvolume(self):
     # print(self.service_dir)
     try:
         ret = sh.btrfs("subvolume", "show", self.service_dir)
     except Exception, e:
         print(e)
         raise BtrfsVolumeError("Invalid subvolume")
Example #7
0
 def _ensure_subvolume(self):
     # print(self.service_dir)
     try:
         ret = sh.btrfs("subvolume", "show", self.service_dir)
     except Exception, e:
         print(e)
         raise BtrfsVolumeError("Invalid subvolume")
Example #8
0
 def free_space(self):
     with self.losetup_context_manager() as device:
         fs = get_filesystem(device)
         with mount_context_manager(device) as mountpoint:
             if fs == 'btrfs':
                 out = btrfs("fi", "usage", "--raw", mountpoint, **SH_OPTS)
                 for line in out:
                     line = line.strip()
                     if line.startswith("Free (estimated):"):
                         return int(line[line.rfind(" ") + 1:-1])
             else:
                 output = df("-B1", "--output=avail", mountpoint, **SH_OPTS)
                 return int(output.split("\n")[1].strip())