Example #1
0
    def test_success(self):
        sync = rsync.rsync()
        sync.dry_run = False

        target = rsync.Path(context.TMP_DIR)
        status = sync.sync(target, [context.TEST_DIR])
        assert status.exit_code == 0
Example #2
0
    def test_includes(self, mock_exec):
        testutils.create_dir_struct({
            'simple.file':
            None,
            'simple folder': {},
            'special * folder': {},
            r'''!"#$%&'()*+,-.012:;<=>?@ABC[\]^_`abc{|}~''':
            None
        })

        sync = rsync.rsync()
        sync.sync(rsync.Path(context.TARGET_DIR), [
            'simple.file',
            'simple folder',
            'special * folder',
            'not found * folder',
            r'test\ \*\ folder/*.pattern',
            r'''!"#$%&'()*+,-.012:;<=>?@ABC[\]^_`abc{|}~''',
        ])

        cmd = mock_exec.call_args[0][0]
        assert b'simple.file' in cmd
        assert b"'simple folder'" in cmd
        assert b"'special * folder'" in cmd
        assert b'not found * folder' in cmd
        assert rb'test\ \*\ folder/*.pattern' in cmd
        assert b"'!"  #$%&' "'" '()*+,-.012:;<=>?@ABC[\]^_`abc{|}~'" in cmd
Example #3
0
    def test_link_dest(self, mock_exec):
        sync = rsync.rsync()
        sync.sync(rsync.Path('/'), [],
                  link_dest='/special * path/previous_backup')

        cmd = mock_exec.call_args[0][0]
        assert b'--delete' in cmd
        assert b"--link-dest '/special * path/previous_backup'" in cmd
Example #4
0
    def test_options_original(self, mock_exec):
        sync = rsync.rsync()
        sync.sync(rsync.Path('/'), [])

        cmd = mock_exec.call_args[0][0]
        assert b'--acls' in cmd
        assert b'--xattrs' in cmd
        assert b'--prune-empty-dirs' in cmd
        assert b"--out-format '%t %i %n'" in cmd
        assert b'--dry-run' in cmd
Example #5
0
    def test_ssh_wrapper(self):
        sync = rsync.rsync()
        sync.ssh_bin = '{} root {}'.format(const.SSH_WRAPPER_SCRIPT,
                                           sync.ssh_bin)
        sync.dry_run = False

        # Send the files
        target = rsync.Path(context.TMP_DIR, context.SSH_HOST)
        status = sync.sync(target, [context.DATA_DIR])

        assert status.exit_code == 0
Example #6
0
    def test_excludes(self, mock_exec):
        sync = rsync.rsync()
        sync.sync(rsync.Path(context.TARGET_DIR), ['/'], [
            '/tmp',
            'simple folder',
            '*.mkv',
        ])

        cmd = mock_exec.call_args[0][0]
        assert b"--exclude /tmp" in cmd
        assert b"--exclude 'simple folder'" in cmd
        assert b"--exclude '*.mkv'" in cmd
Example #7
0
    def test_restore_args(self, mock_sync, target):
        self._create_backup('19900101000000', True)

        with self._io(target) as io:
            bak = backup.Backup.from_name(io, '19900101000000',
                                          context.TARGET_DIR)

            bak.restore('/')
            args = mock_sync.call_args[0]
            assert '/' == args[0].resolved

            item = rsync.Path(bak.backup_data_dir, io.host).resolved
            item = os.path.join(item, './')
            assert item == args[1][0].resolved
Example #8
0
    def test_remote_simple(self):
        sync = rsync.rsync()
        sync.dry_run = False

        # Define the structure we expect after synchronizing
        expected_data = self.data_dir_struct
        del expected_data['test.dir']['dir2']

        # Send the files
        target = rsync.Path(context.TMP_DIR, context.SSH_HOST)
        sync.sync(target, [context.TEST_DIR, context.TEST_FILE],
                  excludes=['**/dir2/.gitkeep'])

        # Get and compare the structure of our sync target
        synced_data = testutils.get_dir_struct(self.real_target)
        assert expected_data == synced_data
Example #9
0
    def test_remote_special_char(self):
        sync = rsync.rsync()
        sync.dry_run = False

        # Define the structure we expect after synchronizing
        expected_data = self.data_dir_struct
        del expected_data[b'test.dir']
        del expected_data[b'test.file']

        # Send the files
        target = rsync.Path(context.TMP_DIR, context.SSH_HOST)
        sync.sync(target, [context.SPECIAL_FILE.decode()])

        # Get and compare the structure of our sync target
        synced_data = test_utils.get_dir_struct(self.real_target.encode())
        self.assertEqual(expected_data, synced_data)
Example #10
0
    def test_local_simple(self):
        sync = rsync.rsync()
        sync.dry_run = False

        # Define the structure we expect after synchronizing
        expected_data = self.data_dir_struct
        del expected_data[b'test.dir'][b'dir2']
        del expected_data[context.SPECIAL_NAME]

        # Send the files
        target = rsync.Path(context.TMP_DIR)
        sync.sync(target, [context.TEST_DIR, context.TEST_FILE],
                  excludes=['**/dir2/.gitkeep'])

        # Get and compare the structure of our sync target
        synced_data = test_utils.get_dir_struct(self.real_target.encode())
        self.assertEqual(expected_data, synced_data)
Example #11
0
    def test_options_modified(self, mock_exec):
        sync = rsync.rsync()

        sync.acls = False
        sync.xattrs = False
        sync.prune_empty_dirs = False
        sync.out_format = "%t %i %f %''b"
        sync.dry_run = False

        sync.sync(rsync.Path('/'), [])

        cmd = mock_exec.call_args[0][0]
        assert b'--acls' not in cmd
        assert b'--xattrs' not in cmd
        assert b'--prune-empty-dirs' not in cmd
        assert '--out-format {}'.format(
            shlex.quote("%t %i %f %''b")).encode() in cmd
        assert b'--dry-run' not in cmd
Example #12
0
    def test_target_local(self, mock_exec):
        sync = rsync.rsync()
        sync.sync(rsync.Path('/backup-target'), [])

        cmd = mock_exec.call_args[0][0]
        assert cmd.endswith(b'/backup-target')
Example #13
0
 def test_resolved_remote(self):
     p = rsync.Path('/tmp', 'localhost')
     assert p.resolved == 'localhost:/tmp'
Example #14
0
 def test_resolved_local(self):
     p = rsync.Path('/tmp')
     assert p.resolved == '/tmp'
Example #15
0
 def test_remote(self):
     p = rsync.Path('/tmp', 'localhost')
     assert not p.is_local
Example #16
0
 def test_remote(self):
     p = rsync.Path(context.TEST_DIR, context.SSH_HOST)
     self.assertTrue(not p.is_local)
Example #17
0
 def test_local(self):
     p = rsync.Path('/tmp')
     assert p.is_local
Example #18
0
    def test_local(self):
        p = rsync.Path(context.TEST_DIR)
        self.assertTrue(p.is_local)

        p = rsync.Path(context.TEST_DIR)
        self.assertTrue(p.is_local)