Example #1
0
 def rescan(self):
     cloned = self.datasets.list_cloned_snapshots()
     self.snapshots = []
     snaplist = self.datasets.list_snapshots()
     for snapname,snaptime in snaplist:
         # Filter out snapshots that are the root
         # of cloned filesystems or volumes
         try:
             cloned.index(snapname)
         except ValueError:
             snapshot = zfs.Snapshot(snapname, snaptime)
             self.snapshots.append(snapshot)
Example #2
0
    def initialise_view(self):
        if len(self.shortcircuit) == 0:
            # Set TreeViews
            self.liststorefs = gtk.ListStore(str, str, str, str, str, long,
                                             gobject.TYPE_PYOBJECT)
            list_filter = self.liststorefs.filter_new()
            list_sort = gtk.TreeModelSort(list_filter)
            list_sort.set_sort_column_id(1, gtk.SORT_ASCENDING)

            self.snaptreeview = self.xml.get_widget("snaplist")
            self.snaptreeview.set_model(self.liststorefs)
            self.snaptreeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)

            cell0 = gtk.CellRendererText()
            cell1 = gtk.CellRendererText()
            cell2 = gtk.CellRendererText()
            cell3 = gtk.CellRendererText()
            cell4 = gtk.CellRendererText()
            cell5 = gtk.CellRendererText()

            typecol = gtk.TreeViewColumn(_("Type"),
                                            cell0, text = 0)
            typecol.set_sort_column_id(0)
            typecol.set_resizable(True)
            typecol.connect("clicked",
                self.__on_treeviewcol_clicked, 0)
            self.snaptreeview.append_column(typecol)

            mountptcol = gtk.TreeViewColumn(_("Mount Point"),
                                            cell1, text = 1)
            mountptcol.set_sort_column_id(1)
            mountptcol.set_resizable(True)
            mountptcol.connect("clicked",
                self.__on_treeviewcol_clicked, 1)
            self.snaptreeview.append_column(mountptcol)

            fsnamecol = gtk.TreeViewColumn(_("File System Name"),
                                           cell2, text = 2)
            fsnamecol.set_sort_column_id(2)
            fsnamecol.set_resizable(True)
            fsnamecol.connect("clicked",
                self.__on_treeviewcol_clicked, 2)
            self.snaptreeview.append_column(fsnamecol)

            snaplabelcol = gtk.TreeViewColumn(_("Snapshot Name"),
                                              cell3, text = 3)
            snaplabelcol.set_sort_column_id(3)
            snaplabelcol.set_resizable(True)
            snaplabelcol.connect("clicked",
                self.__on_treeviewcol_clicked, 3)
            self.snaptreeview.append_column(snaplabelcol)

            cell4.props.xalign = 1.0
            creationcol = gtk.TreeViewColumn(_("Creation Time"),
                                             cell4, text = 4)
            creationcol.set_sort_column_id(5)
            creationcol.set_resizable(True)
            creationcol.connect("clicked",
                self.__on_treeviewcol_clicked, 5)
            self.snaptreeview.append_column(creationcol)

            # Note to developers.
            # The second element is for internal matching and should not
            # be i18ned under any circumstances.
            typestore = gtk.ListStore(str, str)
            typestore.append([_("All"), "All"])
            typestore.append([_("Backups"), "Backup"])
            typestore.append([_("Snapshots"), "Snapshot"])

            self.typefiltercombo = self.xml.get_widget("typefiltercombo")
            self.typefiltercombo.set_model(typestore)
            typefiltercomboCell = gtk.CellRendererText()
            self.typefiltercombo.pack_start(typefiltercomboCell, True)
            self.typefiltercombo.add_attribute(typefiltercomboCell, 'text',0)

            # Note to developers.
            # The second element is for internal matching and should not
            # be i18ned under any circumstances.
            fsstore = gtk.ListStore(str, str)
            fslist = self.datasets.list_filesystems()
            fsstore.append([_("All"), None])
            for fsname,fsmount in fslist:
                fsstore.append([fsname, fsname])
            self.fsfilterentry = self.xml.get_widget("fsfilterentry")
            self.fsfilterentry.set_model(fsstore)
            self.fsfilterentry.set_text_column(0)
            fsfilterentryCell = gtk.CellRendererText()
            self.fsfilterentry.pack_start(fsfilterentryCell)

            schedstore = gtk.ListStore(str, str)
            # Note to developers.
            # The second element is for internal matching and should not
            # be i18ned under any circumstances.
            schedstore.append([_("All"), None])
            schedstore.append([_("Monthly"), "monthly"])
            schedstore.append([_("Weekly"), "weekly"])
            schedstore.append([_("Daily"), "daily"])
            schedstore.append([_("Hourly"), "hourly"])
            schedstore.append([_("1/4 Hourly"), "frequent"])
            self.schedfilterentry = self.xml.get_widget("schedfilterentry")
            self.schedfilterentry.set_model(schedstore)
            self.schedfilterentry.set_text_column(0)
            schedentryCell = gtk.CellRendererText()
            self.schedfilterentry.pack_start(schedentryCell)

            self.schedfilterentry.set_active(0)
            self.fsfilterentry.set_active(0)
            self.typefiltercombo.set_active(0)
        else:
            cloned = self.datasets.list_cloned_snapshots()
            num_snap = 0
            num_rsync = 0
            for snapname in self.shortcircuit:
                # Filter out snapshots that are the root
                # of cloned filesystems or volumes
                try:
                    cloned.index(snapname)
                    dialog = gtk.MessageDialog(None,
                                   0,
                                   gtk.MESSAGE_ERROR,
                                   gtk.BUTTONS_CLOSE,
                                   _("Snapshot can not be deleted"))
                    text = _("%s has one or more dependent clones "
                             "and will not be deleted. To delete "
                             "this snapshot, first delete all "
                             "datasets and snapshots cloned from "
                             "this snapshot.") \
                             % snapname
                    dialog.format_secondary_text(text)
                    dialog.run()
                    sys.exit(1)
                except ValueError:
                    path = os.path.abspath (snapname)
                    if not os.path.exists (path):
                        snapshot = zfs.Snapshot(snapname)
                        self.backuptodelete.append(snapshot)
                        num_snap += 1
                    else:
                        self.backuptodelete.append(RsyncBackup (snapname))
                        num_rsync += 1

            confirm = self.xml.get_widget("confirmdialog")
            summary = self.xml.get_widget("summarylabel")
            total = len(self.backuptodelete)

            text = ""
            if num_rsync != 0 :
                if num_rsync == 1:
                    text = _("1 external backup will be deleted.")
                else:
                    text = _("%d external backups will be deleted.") % num_rsync

            if num_snap != 0 :
                if len(text) != 0:
                    text += "\n"
                if num_snap == 1:
                    text += _("1 snapshot will be deleted.")
                else:
                    text += _("%d snapshots will be deleted.") % num_snap

            summary.set_text(text )
            response = confirm.run()
            if response != 2:
                sys.exit(0)
            else:
                # Create the thread in an idle loop in order to
                # avoid deadlock inside gtk.
                glib.idle_add(self.__init_delete)
        return False
Example #3
0
            # while iterating through it.
            remainingsnaps = snaps[:]
        except RuntimeError, message:
            sys.stderr.write(
                "Failed to list snapshots during snapshot cleanup\n")
            self.exitCode = smf.SMF_EXIT_ERR_FATAL
            raise RuntimeError, message

        if (self._keepEmpties == False):
            try:  # remove the newest one from the list.
                snaps.pop()
            except IndexError:
                pass
            for snapname in snaps:
                try:
                    snapshot = zfs.Snapshot(snapname)
                except Exception, message:
                    sys.stderr.write(str(message))
                    # Not fatal, just skip to the next snapshot
                    continue

                try:
                    if snapshot.get_used_size() == 0:
                        util.debug("Destroying zero sized: " + snapname, \
                                   self.verbose)
                        try:
                            snapshot.destroy()
                        except RuntimeError, message:
                            sys.stderr.write("Failed to destroy snapshot: " +
                                             snapname + "\n")
                            self.exitCode = smf.SMF_EXIT_MON_DEGRADE