def __copylogfile(self):
        # TODO: we should flush the log file before copy!
        _op = fam.get_file_operations_facade_instance()

        if not self.__fam_target_hdl.is_initialized():
            self.logger.warning(
                _("Unable to copy log. File access is not initialized."))
        else:
            if self.__snapshot is not None:
                logf_src = self.config.get_current_logfile()
                if logf_src is None:
                    self.logger.warning(_("No log file specified."))
                else:
                    logf_name = _op.get_basename(logf_src)
                    logf_target = _op.joinpath(self.__snapshot.getPath(),
                                               logf_name)

                    if _op.path_exists(logf_src):
                        try:
                            _op.copyfile(logf_src, logf_target)
                        except exceptions.CopyFileAttributesError:
                            self.logger.warning(_("Unable to change permissions for file '%s'.")\
                                            % logf_target)
                        except (OSError, IOError), error:
                            self.logger.warning(
                                _("Unable to copy log file: %s") % error)
                    else:
                        self.logger.warning(
                            _("Unable to find logfile to copy into snapshot."))
Beispiel #2
0
    def __init__ (self, path):
        """The snapshot constructor.

        :param path : the path to the snapshot dir.

        :todo: Any distinction between creation of a new snapshot and opening\
               an existing one from disk would be useful! The reason is that\
               instantiation a Snapshot with a not existing path creates a\
               snapshot directory in any case, currently! We need to handle the\
               case: opening an snapshot that is supposed to exist but in fact\
               doesn't!

        :todo: Separate commit of snapshot and the snapshot (name, path, ...) itself into
               classes with concise responsibilities.

        """
        self.logger = log.LogFactory.getLogger()
        self._fop = fam.get_file_operations_facade_instance()

        # Attributes
        self.__name = False
        self.__base = None
        self.__format = "none" # default value

        self.__followlinks = False

        self.__snarfile = None

        # explicitely defined include and exclude file lists; these lists are filled from the configuration
        self.__includeFlist = structs.SBdict()
        self.__includeFlistFile = None # Str
        self.__excludeFlist = structs.SBdict()
        self.__excludeFlistFile = None # Str

        self.__space_required = constants.SPACE_REQUIRED_UNKNOWN
        self.__splitedSize = 0
        self.__excludes = False

        self.__packages = False
        self.__version = False
        self.__snapshotpath = None

        self.__baseSnapshot = None

        # set some attributes
        self.setPath(path)    # sets path and validates name

        # check if it's an existing snapshot
        if self._fop.path_exists(self.__snapshotpath):
            self.__validateSnapshot(self.__snapshotpath, self.__name)
        else : # Snapshot for creation
            self._fop.makedir(self.__snapshotpath)
            #LP #785512: make the snapshot directory RWX only by owner
            self._fop.chmod_no_rwx_grp_oth(self.__snapshotpath)
Beispiel #3
0
    def __init__(self, parent=None):
        GladeWindow.__init__(self,
                             gladefile=Util.get_resource_file(
                                 gtk_rsrc.RESTOREGUI_GLADEFILE),
                             widget_list=gtk_rsrc.get_restoregui_widgets(),
                             handlers=gtk_rsrc.get_restoregui_handlers(),
                             root=gtk_rsrc.RESTOREGUI_TOPWINDOW,
                             parent=parent,
                             pull_down_dict=None)
        self.set_top_window(self.widgets[gtk_rsrc.RESTOREGUI_TOPWINDOW])
        Gtk.Window.set_default_icon_from_file(
            Util.get_resource_file(constants.RESTORE_ICON_FILENAME))

        # setup progress bar
        ProgressbarMixin.__init__(self, self.widgets['progressbar'])
        self._init_pulse()

        self.logger = LogFactory.getLogger(level=10)
        self.config = self.__get_configuration()
        self.__default_destination_path = self.config.get_destination_path()

        self.currentSnp = None
        self.currentsbdict = None
        self.currSnpFilesInfos = None
        self.restoreman = None
        self.snpman = None
        self.target = None
        self.__fam_target_hdl = fam.get_fam_target_handler_facade_instance()
        self.__fop = fam.get_file_operations_facade_instance()

        # tree stores
        self.snplisttreestore = Gtk.TreeStore(str, str)
        self.flisttreestore = Gtk.TreeStore(str, str)
        self.flisttreesort = Gtk.TreeModelSort(self.flisttreestore)
        self.historylisttreestore = Gtk.TreeStore(str)
        self.__init_treeviews()

        self.widgets['snpdetails'].set_sensitive(False)

        self.__context_id = None
        self.__init_statusbar()

        # firstly initialize destination with target of default profile
        self._defaultdest_active = True
        self.widgets['defaultradiob'].set_active(True)
        self._apply_defaultradiob_state()
        self.widgets['defaultfolderlabel'].set_text(_("n.a."))
        self._defaultdest_active = True
        GObject.idle_add(self.__set_destination,
                         self.__default_destination_path)

        self.__restore_dialog = RestoreDialog(parent=self)
Beispiel #4
0
def debug_print_snarfile(filename):
    """Print function only for debugging.

    :param filename: full path of snar to be printed out
    :type filename: string

    """
    _fop = fam.get_file_operations_facade_instance()
    if _fop.path_exists(filename):
        _snar = SnapshotFile(filename, writeFlag=False)
        print("\nSUMMARY of SNAR '%s':" % filename)
        for _record in _snar.parseFormat2():
            print("%s" % _record)
    else:
        print("\nSUMMARY of SNAR '%s': file not found!" % filename)
Beispiel #5
0
def debug_snarfile_to_list(filename):
    """Helper function for debugging: the snar-file given by parameter
    'filename' is converted into a list and this list is returned by
    the function.

    :param filename: full path of snar to be converted
    :type filename: string
    :return: list containing snar file entries

    """
    _res = []
    _fop = fam.get_file_operations_facade_instance()
    if _fop.path_exists(filename):
        _snar = SnapshotFile(filename, writeFlag=False)
        for _record in _snar.parseFormat2():
            _res.append(_record)
    return _res
Beispiel #6
0
    def __init__(self, destination):
        """Default constructor. Takes the path to the target backup
        directory as parameter.
        """
        if not isinstance(destination, str):
            raise TypeError("Destination path of type string expected. Got %s instead"\
                            % type(destination))

        self.logger = LogFactory.getLogger()

        self._fop = fam.get_file_operations_facade_instance()
        # This is the current directory used by this SnapshotManager
        self.__dest_path = destination

        # The list of the snapshots is stored the first time it's used,
        # so we don't have to re-get it later
        self.__snapshots = None

        # helper variables for displaying status messages
        self.statusMessage = None
        self.substatusMessage = None
        self.statusNumber = None
Beispiel #7
0
 def __init__(self, targethandler):
     """
     """
     self.logger = log.LogFactory.getLogger()
     self.__fam_target_hdl = targethandler
     self._fop = fam.get_file_operations_facade_instance()
    def __retrieve_basic_infos(self, force_full_snp=False):
        """Retrieves basic informations about the snapshot that is going
        to be created. This informations include:
        1. the path of the new snapshot
        2. the base of the new snapshot
        
        :param listing: a list of snapshots
        
        :return: the determined `snppath` and `base`
        :rtype: a tuple
        
        """
        _fop = fam.get_file_operations_facade_instance()
        # Get the list of snapshots that matches the latest snapshot format
        listing = self.__snpman.get_snapshots()
        agelimit = int(self.config.get("general", "maxincrement"))
        increment = False

        base = None
        if (len(listing) == 0) or (force_full_snp is True):
            increment = False
        else:
            # we got some snaphots
            # we search for the last full
            base = listing[0]
            if listing[0].isfull():  # Last backup was full backup
                self.logger.debug("Last (%s) was a full backup" %
                                  listing[0].getName())
                d = listing[0].getDate()
                age = (datetime.date.today() -
                       datetime.date(d["year"], d["month"], d["day"])).days
                if age < agelimit:
                    # Less than maxincrement days passed since that -> make an increment
                    self.logger.info(
                        "Last full backup is %i days old < %s -> make inc backup"
                        % (age, agelimit))
                    increment = True
                else:
                    self.logger.info(
                        "Last full backup is %i days old > %s -> make full backup"
                        % (age, agelimit))
                    increment = False  # Too old -> make full backup
            else:  # Last backup was an increment - lets search for the last full one
                self.logger.debug(
                    " Last snapshot (%s) was incremental. Lookup of latest full snapshot."
                    % listing[0].getName())
                for i in listing:
                    if i.isfull():
                        d = i.getDate()
                        age = (datetime.date.today() - datetime.date(
                            d["year"], d["month"], d["day"])).days
                        if age < agelimit:
                            # Last full backup is fresh -> make an increment
                            self.logger.info(
                                "Last full backup is fresh (%d days old )-> make an increment"
                                % age)
                            increment = True
                        else:  # Last full backup is old -> make a full backup
                            self.logger.info(
                                "Last full backup is old -> make a full backup"
                            )
                            increment = False
                        break
                else:
                    self.logger.info(
                        "No full backup found -> lets make a full backup to be safe"
                    )
                    increment = False

        # Determine and create backup target directory
        hostname = socket.gethostname()
        snpname = "%s.%s" % (datetime.datetime.now().isoformat("_").replace(
            ":", "."), hostname)
        if increment is True:
            snpname = "%s.inc" % snpname
        else:
            snpname = "%s.ful" % snpname

        tdir = self.__fam_target_hdl.get_snapshot_path(snpname)
        self.logger.debug("Snapshot path: %s" % tdir)

        return (tdir, base)