예제 #1
0
 def testProcLocalToRemote(self):
     """Test mirroring proc remote"""
     procout_dir = os.path.join(abs_test_dir, b"procoutput")
     Myrm(procout_dir)
     procout = rpath.RPath(Globals.local_connection, procout_dir)
     rdiff_backup(True, False, '/proc', procout.path, current_time=10000)
     time.sleep(1)
     rdiff_backup(True, False, '/proc', procout.path, current_time=20000)
     time.sleep(1)
     rdiff_backup(True,
                  False,
                  Local.inc1rp.path,
                  procout.path,
                  current_time=30000)
     self.assertTrue(compare_recursive(Local.inc1rp, procout))
     time.sleep(1)
     rdiff_backup(True, False, '/proc', procout.path, current_time=40000)
예제 #2
0
 def testProcLocal(self):
     """Test initial backup of /proc locally"""
     procout_dir = os.path.join(abs_test_dir, b"procoutput")
     Myrm(procout_dir)
     procout = rpath.RPath(Globals.local_connection, procout_dir)
     rdiff_backup(True, True, '/proc', procout.path, current_time=10000)
     time.sleep(1)
     rdiff_backup(True, True, '/proc', procout.path, current_time=20000)
     time.sleep(1)
     rdiff_backup(True,
                  True,
                  Local.inc1rp.path,
                  procout.path,
                  current_time=30000)
     assert CompareRecursive(Local.inc1rp, procout)
     time.sleep(1)
     rdiff_backup(True, True, '/proc', procout.path, current_time=40000)
예제 #3
0
    def test_ownership_mapping(self):
        """Test --user-mapping-file and --group-mapping-file options"""

        def write_ownership_dir():
            """Write the directory testfiles/root_mapping"""
            rp = rpath.RPath(Globals.local_connection,
                             os.path.join(abs_test_dir, b"root_mapping"))
            re_init_rpath_dir(rp)
            rp1 = rp.append('1')
            rp1.touch()
            rp2 = rp.append('2')
            rp2.touch()
            rp2.chown(userid, 1)  # use groupid 1, usually bin
            return rp

        def write_mapping_files(dir_rp):
            """Write user and group mapping files, return paths"""
            user_map_rp = dir_rp.append('user_map')
            group_map_rp = dir_rp.append('group_map')
            user_map_rp.write_string('root:%s\n%s:root' % (user, user))
            group_map_rp.write_string('0:1')
            return user_map_rp.path, group_map_rp.path

        def get_ownership(dir_rp):
            """Return pair (ids of dir_rp/1, ids of dir_rp2) of ids"""
            rp1, rp2 = list(map(dir_rp.append, ('1', '2')))
            self.assertTrue(rp1.isreg())
            self.assertTrue(rp2.isreg())
            return (rp1.getuidgid(), rp2.getuidgid())

        in_rp = write_ownership_dir()
        user_map, group_map = write_mapping_files(in_rp)
        out_rp = rpath.RPath(Globals.local_connection, abs_output_dir)
        if out_rp.lstat():
            Myrm(out_rp.path)

        self.assertEqual(get_ownership(in_rp), ((0, 0), (userid, 1)))

        rdiff_backup(1,
                     0,
                     in_rp.path,
                     out_rp.path,
                     extra_options=(b"--user-mapping-file %b "
                                    b"--group-mapping-file %b" %
                                    (user_map, group_map)))
        self.assertEqual(get_ownership(out_rp), ((userid, 0), (0, 1)))
예제 #4
0
    def testStatistics(self):
        """Test the writing of statistics

        The file sizes are approximate because the size of directories
        could change with different file systems...

        """
        def sorti(inclist):
            templist = [(inc.getinctime(), inc) for inc in inclist]
            templist.sort()
            return [inc for (t, inc) in templist]

        Globals.compression = 1
        Myrm(abs_output_dir)
        InternalBackup(1, 1, os.path.join(old_test_dir, b"stattest1"),
                       abs_output_dir)
        InternalBackup(1, 1, os.path.join(old_test_dir, b"stattest2"),
                       abs_output_dir,
                       time.time() + 1)

        rbdir = rpath.RPath(Globals.local_connection,
                            os.path.join(abs_output_dir, b"rdiff-backup-data"))

        incs = sorti(restore.get_inclist(rbdir.append("session_statistics")))
        assert len(incs) == 2
        s2 = statistics.StatsObj().read_stats_from_rp(incs[0])
        assert s2.SourceFiles == 7
        assert 700000 <= s2.SourceFileSize < 750000, s2.SourceFileSize
        self.stats_check_initial(s2)

        root_stats = statistics.StatsObj().read_stats_from_rp(incs[1])
        assert root_stats.SourceFiles == 7, root_stats.SourceFiles
        assert 550000 <= root_stats.SourceFileSize < 570000
        assert root_stats.MirrorFiles == 7
        assert 700000 <= root_stats.MirrorFileSize < 750000
        assert root_stats.NewFiles == 1
        assert root_stats.NewFileSize == 0
        assert root_stats.DeletedFiles == 1, root_stats.DeletedFiles
        assert root_stats.DeletedFileSize == 200000
        assert 3 <= root_stats.ChangedFiles <= 4, root_stats.ChangedFiles
        assert 450000 <= root_stats.ChangedSourceSize < 470000
        assert 400000 <= root_stats.ChangedMirrorSize < 420000, \
            root_stats.ChangedMirrorSize
        assert 10 < root_stats.IncrementFileSize < 30000
예제 #5
0
    def testRemoveOlderThanCurrent(self):
        """Make sure --remove-older-than doesn't delete current incs"""
        Myrm(Local.rpout.path)
        assert not os.system(b"cp -a %b %b" %
                             (Local.backup3rp.path, Local.rpout.path))
        rdiff_backup(True,
                     True,
                     Local.rpout.path,
                     None,
                     extra_options=b"--remove-older-than now --force")
        rbdir = Local.rpout.append("rdiff-backup-data")

        has_cur_mirror, has_metadata = 0, 0
        for inc in self.get_all_increments(rbdir):
            if inc.getincbase().index[-1] == b'current_mirror':
                has_cur_mirror = 1
            elif inc.getincbase().index[-1] == b'mirror_metadata':
                has_metadata = 1
        assert has_cur_mirror and has_metadata, (has_cur_mirror, has_metadata)
예제 #6
0
    def make_unreadable(self):
        """Make unreadable input directory

        The directory needs to be readable initially (otherwise it
        just won't get backed up, and then later we will turn it
        unreadable.

        """
        rp = rpath.RPath(Globals.local_connection,
                         os.path.join(abs_test_dir, b"regress"))
        if rp.lstat():
            Myrm(rp.path)
        rp.setdata()
        rp.mkdir()
        rp1 = rp.append('unreadable_dir')
        rp1.mkdir()
        rp1_1 = rp1.append('to_be_unreadable')
        rp1_1.write_string('aensuthaoeustnahoeu')
        return rp
예제 #7
0
    def test_length_limit(self):
        """Confirm that length limit is max_len

        Some of these tests depend on the length being at most
        max_len, so check to make sure it's accurate.

        """
        Myrm(self.out_rp.path)
        self.out_rp.mkdir()

        really_long = self.out_rp.append('a' * max_len)
        really_long.touch()

        try:
            self.out_rp.append("a" * (max_len + 1))
        except EnvironmentError as e:
            assert e.errno == errno.ENAMETOOLONG, e
        else:
            assert 0, "File made successfully with length " + str(max_len + 1)
예제 #8
0
    def test_length_limit(self):
        """Confirm that length limit is NAME_MAX_LEN

        Some of these tests depend on the length being at most
        NAME_MAX_LEN, so check to make sure it's accurate.

        """
        Myrm(self.out_rp.path)
        self.out_rp.mkdir()

        really_long = self.out_rp.append('a' * NAME_MAX_LEN)
        really_long.touch()

        with self.assertRaises(
                OSError,
                msg="File name could exceed max length '{max}'.".format(
                    max=NAME_MAX_LEN)) as cm:
            self.out_rp.append("a" * (NAME_MAX_LEN + 1)).touch()
        self.assertEqual(cm.exception.errno, errno.ENAMETOOLONG)
예제 #9
0
 def testRemoveOlderThanQuoting(self):
     """Test --remove-older-than when dest directory is quoted"""
     Myrm(Local.rpout.path)
     rdiff_backup(True,
                  True,
                  Local.inc1rp.path,
                  Local.rpout.path,
                  extra_options=b"--override-chars-to-quote '^a-z0-9_ -.'"
                  b" --current-time 10000")
     rdiff_backup(True,
                  True,
                  Local.inc2rp.path,
                  Local.rpout.path,
                  extra_options=b"--override-chars-to-quote '^a-z0-9_ -.'"
                  b" --current-time 20000")
     rdiff_backup(True,
                  True,
                  Local.rpout.path,
                  None,
                  extra_options=b"--remove-older-than now")
예제 #10
0
    def test_unreadable(self):
        """Run regress test when regular file is unreadable"""
        self.output_rp.setdata()
        if self.output_rp.lstat():
            Myrm(self.output_rp.path)
        unreadable_rp = self.make_unreadable()

        rdiff_backup(1,
                     1,
                     unreadable_rp.path,
                     self.output_rp.path,
                     current_time=1)
        rbdir = self.output_rp.append('rdiff-backup-data')
        marker = rbdir.append('current_mirror.2000-12-31T21:33:20-07:00.data')
        marker.touch()
        self.change_unreadable()

        cmd = b"rdiff-backup --check-destination-dir %s" % self.output_rp.path
        print("Executing:", cmd)
        self.assertEqual(os_system(cmd), 0)
예제 #11
0
    def test_numerical_mapping(self):
        """Test --preserve-numerical-ids option

        This doesn't really test much, since we don't have a
        convenient system with different uname/ids.

        """

        def write_ownership_dir():
            """Write the directory testfiles/root_mapping"""
            rp = rpath.RPath(Globals.local_connection,
                             os.path.join(abs_test_dir, b"root_mapping"))
            re_init_rpath_dir(rp)
            rp1 = rp.append('1')
            rp1.touch()
            rp2 = rp.append('2')
            rp2.touch()
            rp2.chown(userid, 1)  # use groupid 1, usually bin
            return rp

        def get_ownership(dir_rp):
            """Return pair (ids of dir_rp/1, ids of dir_rp2) of ids"""
            rp1, rp2 = list(map(dir_rp.append, ('1', '2')))
            self.assertTrue(rp1.isreg())
            self.assertTrue(rp2.isreg())
            return (rp1.getuidgid(), rp2.getuidgid())

        in_rp = write_ownership_dir()
        out_rp = rpath.RPath(Globals.local_connection, abs_output_dir)
        if out_rp.lstat():
            Myrm(out_rp.path)

        self.assertEqual(get_ownership(in_rp), ((0, 0), (userid, 1)))

        rdiff_backup(1,
                     0,
                     in_rp.path,
                     out_rp.path,
                     extra_options=(b"--preserve-numerical-ids"))
        self.assertEqual(get_ownership(out_rp), ((0, 0), (userid, 1)))
예제 #12
0
    def setUp(self):
        """Make testfiles/output directory and a few files"""
        Myrm(abs_output_dir)
        self.outputrp = rpath.RPath(Globals.local_connection, abs_output_dir)
        self.regfile1 = self.outputrp.append("reg1")
        self.regfile2 = self.outputrp.append("reg2")
        self.regfile3 = self.outputrp.append("reg3")

        self.outputrp.mkdir()

        with self.regfile1.open("wb") as fp:
            fp.write(b"hello")
        self.regfile1.setfile(self.regfile1.open("rb"))

        self.regfile2.touch()
        self.regfile2.setfile(self.regfile2.open("rb"))

        with self.regfile3.open("wb") as fp:
            fp.write(b"goodbye")
        self.regfile3.setfile(self.regfile3.open("rb"))

        self.regfile1.setdata()
        self.regfile2.setdata()
        self.regfile3.setdata()
예제 #13
0
 def testProcRemoteToLocal(self):
     """Test mirroring proc, this time when proc is remote, dest local"""
     procout_dir = os.path.join(abs_test_dir, b"procoutput")
     Myrm(procout_dir)
     procout = rpath.RPath(Globals.local_connection, procout_dir)
     rdiff_backup(False, True, '/proc', procout.path)
예제 #14
0
        (nestedout_dir, output_desc)
    print("Initial rsync: %ss" % (run_cmd(rsync_command), ))
    print("rsync update: %ss" % (run_cmd(rsync_command), ))

    create_nested(nestedout_dir, "e", depth)
    print("Update changed rsync: %ss" % (run_cmd(rsync_command), ))


if len(sys.argv) < 2 or len(sys.argv) > 3:
    print("Syntax:  benchmark.py benchmark_func [output_description]")
    print("")
    print("Where output_description defaults to '%s'." % abs_output_dir)
    print("Currently benchmark_func includes:")
    print("'many_files', 'many_files_rsync', and, 'nested_files'.")
    sys.exit(1)

if len(sys.argv) == 3:
    output_desc = os.fsencode(sys.argv[2])
    if b":" not in output_desc:  # file is local
        assert not rpath.RPath(Globals.local_connection, output_desc).lstat(), \
            "Outfile file '%a' exists, try deleting it first." % (output_desc,)
else:  # we assume we can always remove the default output directory
    Myrm(output_desc)

if 'BENCHMARKPYPATH' in os.environ:
    new_pythonpath = os.fsencode(os.environ['BENCHMARKPYPATH'])

function_name = sys.argv[1]
print("Running ", function_name)
eval(sys.argv[1])()