示例#1
0
文件: zfs.py 项目: gclawes/tardis
    def get_config(self):
        """load com.sun:auto-snapshot settings
        for all zfs filesystems"""
        raw_config = zfs_cmd.get("-o", "name,property,value", "-t", "filesystem", "all")

        p = re.compile(".* com.sun:auto-snapshot.*")
        subst = re.compile("com.sun:")

        config = {}

        for i in p.findall(raw_config.stdout):
            s = i.split()
            if len(s) == 3:
                name = s[0]
                prop = subst.sub("", s[1])
                if s[2] == "true":
                    value = True
                elif s[2] == "false":
                    value = False
                else:
                    log.error(
                        "improper value for com.sun:auto-snapshot property, assuming false: %s %s %s"
                        % (name, prop, value)
                    )
                    value = False

                if name in config.keys():
                    config[name][prop] = value
                else:
                    config[name] = {prop: value}

        return config
示例#2
0
文件: zfs.py 项目: gclawes/tardis
    def destroy_snapshot(self, name):
        """callout to zfs command to destroy snapshot"""
        # name = "%s@%s" % (filesystem, interval)

        if env.DRY_RUN:
            log.info("dry-run: would destroy %s" % name)
        else:
            log.debug("destroy_snapshot(%s)" % (name))
            if "@" in name:
                zfs_cmd.destroy(name)
            else:
                log.error("should not be destroying a dataset! name: %s" % name)
示例#3
0
文件: btrfs.py 项目: gclawes/tardis
    def destroy_snapshot(self, name):
        """callout to btrfs command to destroy snapshot"""

        if env.DRY_RUN:
            log.info("dry-run: would destroy %s" % name)
        else:
            log.debug("destroy_snapshot(%s)" % (name))
            if os.access(name, os.F_OK):
                if "/.btrfs-auto-snap/" in name:
                    btrfs_cmd.subvolume.delete(name)
                else:
                    log.error("should not be destroying a dataset! name: %s" % name)
            else:
                log.error("cannot find %s" % name)
示例#4
0
文件: zfs.py 项目: gclawes/tardis
    def commit_snapshot(self, filesystem, interval, label):
        """call out to zfs command to create snapshot
        return a Snapshot object"""

        name = "%s@zfs-auto-snap_%s-%s" % (filesystem, interval, label)
        current_snapshots = [s.name for s in self.get_snapshots()]

        if name in current_snapshots:
            log.error("snapshot %s already exists, not overwriting!" % name)
            return

        if env.DRY_RUN:
            log.info("dry-run: would commit %s" % name)
        else:
            log.debug("commit_snapshot(%s, %s, %s)" % (filesystem, interval, label))
            zfs_cmd.snapshot(name)
示例#5
0
文件: btrfs.py 项目: gclawes/tardis
    def commit_snapshot(self, dataset, interval, label):
        """call out to btrfs command to create snapshot
        return a Snapshot object"""

        snap_dir = os.path.join(dataset, '.btrfs-auto-snap')
        interval_dir = os.path.join(snap_dir, interval)
        destination = os.path.join(interval_dir, label)

        if os.path.exists(destination):
            log.error("snapshot %s already exists, not overwriting!" % destination)
            return

        # if interval_dir isn't a directory, and also isn't a file with that name
        # create the snapshot label directory
        if not os.path.isdir(interval_dir) and not os.path.exists(interval_dir):
            s = os.stat(snap_dir)
            os.mkdir(interval_dir)
            os.chown(interval_dir, s[stat.ST_UID], s[stat.ST_GID])

        if env.DRY_RUN:
            log.info("dry-run: would commit %s" % (destination))
        else:
            log.debug("commit_snapshot(%s, %s, %s)" % (dataset, interval, label))
            btrfs_cmd.subvolume.snapshot(dataset, destination)
示例#6
0
from fnmatch import filter

from tardis import log
from tardis.fs import Filesystem

mod_files = filter(os.listdir(os.path.dirname(__file__)), "*.py")
mod_files.remove('__init__.py')
names = [f[:-3] for f in mod_files]

loaded_modules = {}
for mod_name in names:
    fd, pathname, description = imp.find_module(mod_name, __path__)
    try:
        module = imp.load_module("%s.%s" % (__name__, mod_name),
                                 fd, pathname, description)
        loaded_modules[mod_name] = module
    except:
        log.error("Error importing %s" % mod_name)
        raise
    finally:
        fd.close()

if not loaded_modules:
    raise Exception("ERROR: no filesystems enabled!")


def load_plugins():
    """Loads filesystem plugins.  Returns a list of instances"""
    return {p.__module__.split('.')[-1]: p()
            for p in Filesystem.__subclasses__() if p.is_enabled()}