Esempio n. 1
0
File: fs.py Progetto: gclawes/tardis
 def purge_old_snapshots(self, interval, keep):
     old_snapshots = self.get_old_snapshots(int(keep), interval)
     if old_snapshots != []:
         log.info("purging old snapshots: %s" %
                 (' '.join([str(s) for s in old_snapshots])))
         for s in old_snapshots:
             s.destroy()
Esempio n. 2
0
File: fs.py Progetto: gclawes/tardis
 def clean_zero_size_snapshots(self, interval_name):
     #all_snapshots = self.get_snapshots()
     for d in self.get_datasets():
         d_snapshots = self.filter_snapshots(dataset=d, interval=interval_name)[:-1]
         for s in d_snapshots:
             if s.size == "0":
                 log.info("destroying zero-sized snapshot: %s" % s)
                 s.destroy()
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)