Beispiel #1
0
    def test_remove_older_than(self):
        """Test removing old backup chains"""
        self.deltmp()
        self.backup("full", "testfiles/dir1", current_time=10000)
        self.backup("inc", "testfiles/dir2", current_time=20000)
        self.backup("full", "testfiles/dir1", current_time=30000)
        self.backup("inc", "testfiles/dir3", current_time=40000)

        b = duplicity.backend.get_backend(backend_url)
        commandline.set_archive_dir("testfiles/cache")
        cs = collections.CollectionsStatus(b, globals.archive_dir).set_values()
        assert len(cs.all_backup_chains) == 2, cs.all_backup_chains
        assert cs.matched_chain_pair

        self.run_duplicity(["--force", backend_url],
                           options=["remove-older-than 35000"])
        cs2 = collections.CollectionsStatus(b,
                                            globals.archive_dir).set_values()
        assert len(cs2.all_backup_chains) == 1, cs.all_backup_chains
        assert cs2.matched_chain_pair
        chain = cs2.all_backup_chains[0]
        assert chain.start_time == 30000, chain.start_time
        assert chain.end_time == 40000, chain.end_time

        # Now check to make sure we can't delete only chain
        self.run_duplicity(["--force", backend_url],
                           options=["remove-older-than 50000"])
        cs3 = collections.CollectionsStatus(b,
                                            globals.archive_dir).set_values()
        assert len(cs3.all_backup_chains) == 1
        assert cs3.matched_chain_pair
        chain = cs3.all_backup_chains[0]
        assert chain.start_time == 30000, chain.start_time
        assert chain.end_time == 40000, chain.end_time
Beispiel #2
0
    def get_filelist2_cs(self):
        u"""Return set CollectionsStatus object from filelist 2"""
        # Set up testfiles/output with files from filename_list2
        for filename in filename_list2:
            p = self.output_dir.append(filename)
            p.touch()

        cs = collections.CollectionsStatus(self.output_dir_backend,
                                           globals.archive_dir_path, u"full")
        cs.set_values()
        return cs
Beispiel #3
0
    def get_filelist2_cs(self):
        """Return set CollectionsStatus object from filelist 2"""
        # Set up testfiles/output with files from filename_list2
        self.del_tmp()
        for filename in filename_list2:
            p = output_dir.append(filename)
            p.touch()

        cs = collections.CollectionsStatus(output_dir_backend, archive_dir)
        cs.set_values()
        return cs
    def test_collections_status(self):
        """Test CollectionStatus object's set_values()"""
        def check_cs(cs):
            """Check values of collections status"""
            assert cs.values_set

            assert cs.matched_chain_pair
            assert cs.matched_chain_pair[0].end_time == 1029826800
            assert len(cs.all_backup_chains) == 1, cs.all_backup_chains

        cs = collections.CollectionsStatus(self.real_backend,
                                           globals.archive_dir).set_values()
        check_cs(cs)
        assert cs.matched_chain_pair[0].islocal()
    def test_backup_chains(self):
        """Test basic backup chain construction"""
        random.shuffle(filename_list1)
        cs = collections.CollectionsStatus(None, globals.archive_dir)
        chains, orphaned, incomplete = cs.get_backup_chains(
            filename_list1)  # @UnusedVariable
        if len(chains) != 1 or len(orphaned) != 0:
            print chains
            print orphaned
            assert 0

        chain = chains[0]
        assert chain.end_time == 1029654270
        assert chain.fullset.time == 1029626221
Beispiel #6
0
 def runduplicity(self):
     if self.url is None:
         return
     log.setup()
     log.setverbosity(int(self.debuglevel))
     if self.passphrasefd:
         self.passphrasefd = int(self.passphrasefd)
     if self.passwordfd:
         self.passwordfd = int(self.passwordfd)
     if self.url.find("file:/") != 0:
         get_backendpassphrase(self.passwordfd)
     opts = []
     for i in self.options:
         try:
             v = eval("self." + i.replace("-", ""))
             if v:
                 opts.append("--%s=%s" % (i, v))
         except:
             pass
     for i in self.no_options:
         try:
             v = eval("self." + i.replace("-", ""))
             if v:
                 opts.append("--%s" % (i))
         except:
             pass
     self.options = []
     parameter = ["list-current-files", "--ssh-askpass"] + opts + [self.url]
     log.Log("processing %s" % (" ".join(parameter)), 5)
     sys.argv = ["duplicity"] + parameter
     action = commandline.ProcessCommandLine(parameter)
     log.Log("running action %s" % (action), 5)
     globals.gpg_profile.passphrase = get_passphrase(self.passphrasefd)
     self.col_stats = collections.CollectionsStatus(
         globals.backend, globals.archive_dir,
         "collection-status").set_values()
     self.date_types = []
     for chain in self.col_stats.all_backup_chains:
         for s in chain.get_all_sets():
             self.date_types.append(
                 (datetime.fromtimestamp(s.get_time()), s.type))
     for s in self.date_types:
         self.dircache[date2str(s[0]) + '_' + s[1]] = None
Beispiel #7
0
    def runduplicity(self):
        if not self.url:
            return
        duplicity_log.setup()
        duplicity_log.setverbosity(int(self.debuglevel))
        log.addHandler(logging.handlers.SysLogHandler(address='/dev/log'))

        if self.passphrasefd:
            self.passphrasefd = int(self.passphrasefd)
        if self.passwordfd:
            self.passwordfd = int(self.passwordfd)
        if self.url.find("file:/") != 0:
            get_backendpassphrase(self.passwordfd)
        opts = []
        self_dict = vars(self)
        for option in self.options:
            value = self_dict.get(option.replace("-", ""))
            if value:
                opts.append("--%s=%s" % (option, value))
        for option in self.no_options:
            if option.replace("-", "") in self_dict:
                opts.append("--%s" % (option))
        self.options = []
        parameter = ["list-current-files", "--ssh-askpass"] + opts + [self.url]
        debug_log("processing %s" % (" ".join(parameter)))
        sys.argv = ["duplicity"] + parameter
        action = commandline.ProcessCommandLine(parameter)
        debug_log("running action %s" % (action))
        globals.gpg_profile.passphrase = get_passphrase(self.passphrasefd)
        self.col_stats = collections.CollectionsStatus(
            globals.backend, globals.archive_dir,
            "collection-status").set_values()
        self.date_types = [(datetime.fromtimestamp(s.get_time()), s.type)
                           for chain in self.col_stats.all_backup_chains
                           for s in chain.get_all_sets()]
        self.dircache.update({(date2str(timestamp) + '_' + type): None
                              for timestamp, type in self.date_types})
        debug_log("initialized cache: " + str(self.date_types) + ", " +
                  str(self.dircache))
Beispiel #8
0
 def test_sig_chains2(self):
     u"""Test making signature chains from filename list on backend"""
     cs = collections.CollectionsStatus(self.archive_dir_backend,
                                        globals.archive_dir_path, u"full")
     chains, orphaned_paths = cs.get_signature_chains(local=None)
     self.sig_chains_helper(chains, orphaned_paths)
 def test_sig_chains(self):
     """Test making signature chains from filename list"""
     cs = collections.CollectionsStatus(None, globals.archive_dir)
     chains, orphaned_paths = cs.get_signature_chains(local=1)
     self.sig_chains_helper(chains, orphaned_paths)