コード例 #1
0
    def test_action_regress(self):
        """test different ways of regressing"""
        # regressing a successful backup doesn't do anything
        self.assertEqual(
            comtst.rdiff_backup_action(False, None, self.bak_path, None,
                                       ("--api-version", "201"), b"regress",
                                       ()), 0)
        # we again simulate a crash
        _repo_shadow.ShadowRepo.touch_current_mirror(
            rpath.RPath(Globals.local_connection, self.bak_path,
                        ("rdiff-backup-data", )), Time.timetostring(20000))
        # the current process (the test) is still running, hence it fails
        self.assertNotEqual(
            comtst.rdiff_backup_action(True, None, self.bak_path, None,
                                       ("--api-version", "201"), b"regress",
                                       ()), 0)
        # but it runs with --force
        self.assertEqual(
            comtst.rdiff_backup_action(True, None, self.bak_path, None,
                                       ("--api-version", "201", "--force"),
                                       b"regress", ()), 0)
        # we restore and compare
        self.assertEqual(
            comtst.rdiff_backup_action(True, True, self.bak_path,
                                       self.to2_path, ("--api-version", "201"),
                                       b"restore", ()), 0)
        self.assertFalse(fileset.compare_paths(self.from2_path, self.to2_path))
        # we again simulate a crash
        _repo_shadow.ShadowRepo.touch_current_mirror(
            rpath.RPath(Globals.local_connection, self.bak_path,
                        ("rdiff-backup-data", )), Time.timetostring(10000))
        # and then try to backup, which fails because without force
        self.assertNotEqual(
            comtst.rdiff_backup_action(
                True, True, self.from4_path, self.bak_path,
                ("--api-version", "201", "--current-time", "40000"), b"backup",
                ()), 0)
        # now with --force, it can't be exactly the same time or it fails
        # on error_log already existing
        self.assertEqual(
            comtst.rdiff_backup_action(
                True, True, self.from4_path, self.bak_path,
                ("--api-version", "201", "--current-time", "40001", "--force"),
                b"backup", ()), 0)
        # we restore and compare
        self.assertEqual(
            comtst.rdiff_backup_action(True, True, self.bak_path,
                                       self.to4_path, ("--api-version", "201"),
                                       b"restore", ()), 0)
        self.assertFalse(fileset.compare_paths(self.from4_path, self.to4_path))

        # all tests were successful
        self.success = True
コード例 #2
0
    def mark_incomplete(self, curtime, rp):
        """Check the date of current mirror

        Return 1 if there are two current_mirror incs and last one has
        time curtime.  Return 0 if only one with time curtime, and
        then add a current_mirror marker.  Return -1 if only one and
        time is not curtime.

        """
        rbdir = rp.append_path("rdiff-backup-data")
        inclist = restore.get_inclist(rbdir.append("current_mirror"))
        assert 1 <= len(inclist) <= 2, str([x.path for x in inclist])

        inc_date_pairs = [(inc.getinctime(), inc) for inc in inclist]
        inc_date_pairs.sort()
        if len(inclist) == 2:
            assert inc_date_pairs[-1][0] == curtime, \
                (inc_date_pairs[-1][0], curtime)
            return 1

        if inc_date_pairs[-1][0] == curtime:
            result = 0
            marker_time = curtime - 10000
        else:
            assert inc_date_pairs[-1][0] == curtime - 10000
            marker_time = curtime
            result = -1

        cur_mirror_rp = rbdir.append("current_mirror.%s.data" %
                                     (Time.timetostring(marker_time), ))
        assert not cur_mirror_rp.lstat()
        cur_mirror_rp.touch()
        return result
コード例 #3
0
 def testStringtotime(self):
     """Test converting string to time"""
     timesec = int(time.time())
     assert timesec == int(Time.stringtotime(Time.timetostring(timesec)))
     assert not Time.stringtotime("2001-18-83T03:03:03Z")
     assert not Time.stringtotime("2001-01-23L03:03:03L")
     assert not Time.stringtotime("2001_01_23T03:03:03Z")
コード例 #4
0
ファイル: killtest.py プロジェクト: user-na/rdiff-backup
    def mark_incomplete(self, curtime, rp):
        """Check the date of current mirror

        Return 1 if there are two current_mirror incs and last one has
        time curtime.  Return 0 if only one with time curtime, and
        then add a current_mirror marker.  Return -1 if only one and
        time is not curtime.

        """
        rbdir = rp.append_path("rdiff-backup-data")
        inclist = restore.get_inclist(rbdir.append("current_mirror"))
        self.assertIn(
            len(inclist), (1, 2),
            "There must be 1 or 2 elements in '{paths_list}'.".format(
                paths_list=str([x.path for x in inclist])))

        inc_date_pairs = [(inc.getinctime(), inc) for inc in inclist]
        inc_date_pairs.sort()
        if len(inclist) == 2:
            self.assertEqual(inc_date_pairs[-1][0], curtime)
            return 1

        if inc_date_pairs[-1][0] == curtime:
            result = 0
            marker_time = curtime - 10000
        else:
            self.assertEqual(inc_date_pairs[-1][0], curtime - 10000)
            marker_time = curtime
            result = -1

        cur_mirror_rp = rbdir.append("current_mirror.%s.data" %
                                     (Time.timetostring(marker_time), ))
        self.assertFalse(cur_mirror_rp.lstat())
        cur_mirror_rp.touch()
        return result
コード例 #5
0
ファイル: timetest.py プロジェクト: ObiWahn/rdiff-backup
	def testStringtotime(self):
		"""Test converting string to time"""
		timesec = int(time.time())
		assert timesec == int(Time.stringtotime(Time.timetostring(timesec)))
		assert not Time.stringtotime("2001-18-83T03:03:03Z")
		assert not Time.stringtotime("2001-01-23L03:03:03L")
		assert not Time.stringtotime("2001_01_23T03:03:03Z")
コード例 #6
0
ファイル: timetest.py プロジェクト: rdiff-backup/rdiff-backup
 def testStringtotime(self):
     """Test converting string to time"""
     timesec = int(time.time())
     self.assertEqual(timesec,
                      int(Time.stringtotime(Time.timetostring(timesec))))
     # stringtotime returns None if the time string is invalid
     self.assertIsNone(Time.stringtotime("2001-18-83T03:03:03Z"))
     self.assertIsNone(Time.stringtotime("2001-01-23L03:03:03L"))
     self.assertIsNone(Time.stringtotime("2001_01_23T03:03:03Z"))
コード例 #7
0
    def testBytestotime(self):
        """Test converting byte string to time"""
        timesec = int(time.time())
        assert timesec == int(
            Time.bytestotime(Time.timetostring(timesec).encode('ascii')))

        # assure that non-ascii byte strings return None and that they don't
        # throw an exception (issue #295)
        assert Time.bytestotime(b'\xff') is None
コード例 #8
0
    def test_symlink_popple(self):
        """Test for Popple's symlink bug

        Earlier, certain symlinks could cause data loss in _source_
        directory when regressing.  See mailing lists around 4/2/05
        for more info.

        """
        self.delete_tmpdirs()

        # Make directories
        rp1 = Local.get_tgt_local_rp('sym_in1')
        if rp1.lstat():
            rp1.delete()
        rp1.mkdir()
        rp1_d = rp1.append('subdir')
        rp1_d.mkdir()
        rp1_d_f = rp1_d.append('file')
        rp1_d_f.touch()

        rp2 = Local.get_tgt_local_rp('sym_in2')
        if rp2.lstat():
            rp2.delete()
        rp2.mkdir()
        rp2_s = rp2.append('subdir')
        rp2_s.symlink("%s/%s" % (abs_test_dir, rp1_d.path))

        # Backup
        rdiff_backup(True,
                     True,
                     rp1.path,
                     Local.rpout.path,
                     current_time=10000)
        rdiff_backup(True,
                     True,
                     rp2.path,
                     Local.rpout.path,
                     current_time=20000)

        # Make failed backup
        rbdir = Local.rpout.append('rdiff-backup-data')
        curmir = rbdir.append('current_mirror.%s.data' %
                              (Time.timetostring(30000), ))
        curmir.touch()

        # Regress
        rdiff_backup(True,
                     True,
                     Local.rpout.path,
                     None,
                     current_time=30000,
                     extra_options=b'--check-destination-dir')

        # Check to see if file still there
        rp1_d_f.setdata()
        assert rp1_d_f.isreg(), 'File %a corrupted' % (rp1_d_f.path, )
コード例 #9
0
 def testConversion(self):
     """test timetostring and stringtotime"""
     Time.setcurtime()
     assert type(Time.curtime) is types.FloatType or types.LongType
     assert type(Time.curtimestr) is types.StringType
     assert (Time.cmp(int(Time.curtime), Time.curtimestr) == 0
             or Time.cmp(int(Time.curtime) + 1, Time.curtimestr) == 0)
     time.sleep(1.05)
     assert Time.cmp(time.time(), Time.curtime) == 1
     assert Time.cmp(Time.timetostring(time.time()), Time.curtimestr) == 1
コード例 #10
0
 def testConversion(self):
     """test timetostring and stringtotime"""
     Time.setcurtime()
     assert type(Time.curtime) is float or int, Time.curtime
     assert type(Time.curtimestr) is str, Time.curtimestr
     assert (Time.cmp(int(Time.curtime), Time.curtimestr) == 0
             or Time.cmp(int(Time.curtime) + 1, Time.curtimestr) == 0)
     time.sleep(1.05)
     assert Time.cmp(time.time(), Time.curtime) == 1
     assert Time.cmp(Time.timetostring(time.time()), Time.curtimestr) == 1
コード例 #11
0
ファイル: timetest.py プロジェクト: ObiWahn/rdiff-backup
	def testConversion(self):
		"""test timetostring and stringtotime"""
		Time.setcurtime()
		assert type(Time.curtime) is types.FloatType or types.LongType
		assert type(Time.curtimestr) is types.StringType
		assert (Time.cmp(int(Time.curtime), Time.curtimestr) == 0 or
				Time.cmp(int(Time.curtime) + 1, Time.curtimestr) == 0)
		time.sleep(1.05)
		assert Time.cmp(time.time(), Time.curtime) == 1
		assert Time.cmp(Time.timetostring(time.time()), Time.curtimestr) == 1
コード例 #12
0
ファイル: timetest.py プロジェクト: rdiff-backup/rdiff-backup
 def testConversion(self):
     """test timetostring and stringtotime"""
     Time.set_current_time()
     self.assertIsInstance(Time.curtime, (float, int))
     self.assertIsInstance(Time.curtimestr, str)
     self.assertTrue(
         self.cmp_times(int(Time.curtime), Time.curtimestr) == 0
         or self.cmp_times(int(Time.curtime) + 1, Time.curtimestr) == 0)
     time.sleep(1.05)
     self.assertEqual(self.cmp_times(time.time(), Time.curtime), 1)
     self.assertEqual(
         self.cmp_times(Time.timetostring(time.time()), Time.curtimestr), 1)
コード例 #13
0
    def force_regress(self):
        """
        Try to fake a failed backup to force a regress

        Return True if the fake was succesful, else False, e.g. if the
        repository contains only the mirror and no increment.
        """
        inc_times = self.get_increment_times()
        if len(inc_times) < 2:
            log.Log(
                "Repository with only a mirror can't be forced to regress, "
                "just remove it and start from scratch", log.WARNING)
            return False
        mirror_time = self.get_mirror_time()
        if inc_times[-1] != mirror_time:
            log.Log(
                "Repository's increment times are inconsistent, "
                "it's too dangerous to force a regress", log.WARNING)
            return False
        self.touch_current_mirror(Time.timetostring(inc_times[-2]))
        return True
コード例 #14
0
 def add_current_mirror(self, time):
     """Add current_mirror marker at given time"""
     cur_mirror_rp = self.output_rbdir_rp.append(
         "current_mirror.%s.data" % (Time.timetostring(time), ))
     cur_mirror_rp.touch()
コード例 #15
0
 def addtostr(s):
     return b'.'.join(map(os.fsencode,
                          (s, Time.timetostring(inc_time), typestr)))
コード例 #16
0
ファイル: regresstest.py プロジェクト: ObiWahn/rdiff-backup
	def add_current_mirror(self, time):
		"""Add current_mirror marker at given time"""
		cur_mirror_rp = self.output_rbdir_rp.append(
			"current_mirror.%s.data" % (Time.timetostring(time),))
		cur_mirror_rp.touch()