def testRunCustomWorkflow_sourceHostnameIsLocalhost_sourceIsPath(self):
        FLAGS.rdiff_backup_path = '/fake/rdiff-backup'
        FLAGS.backup_store_path = '/fake/backup-store'
        FLAGS.top_level_src_dir = '/'
        mock_command_runner = test_lib.GetMockCommandRunner()
        backup = rdiff_backup_wrapper.RdiffBackup(
            label='fake_backup',
            source_hostname='localhost',
            settings_path=None,
            command_runner=mock_command_runner)

        backup.include('/fake_dir')
        backup.run()

        mock_command_runner.run.assert_called_once_with([
            '/fake/rdiff-backup', '--include', '/fake_dir', '--exclude', '**',
            '/', '/fake/backup-store/fake_backup'
        ], False)
    def testRemoveOlderThan_timespecOverriddenViaAttribute_usesOverriddenValue(
            self):
        FLAGS.rdiff_backup_path = '/fake/rdiff-backup'
        FLAGS.backup_store_path = '/fake/backup-store'
        FLAGS.remove_older_than_timespec = '60D'
        mock_command_runner = test_lib.GetMockCommandRunner()
        backup = rdiff_backup_wrapper.RdiffBackup(
            label='fake_backup',
            source_hostname='unused',
            settings_path=None,
            command_runner=mock_command_runner)

        backup.include('/unused')
        backup.remove_older_than_timespec = '365D'
        backup.run()

        mock_command_runner.run.assert_called_with([
            '/fake/rdiff-backup', '--force', '--remove-older-than', '365D',
            '/fake/backup-store/fake_backup'
        ], False)
    def testExclude_backupExcludesPaths(self):
        FLAGS.rdiff_backup_path = '/fake/rdiff-backup'
        FLAGS.backup_store_path = '/fake/backup-store'
        FLAGS.top_level_src_dir = '/'
        mock_command_runner = test_lib.GetMockCommandRunner()
        # Note that setting source_hostname to 'localhost' prevents the command
        # that is run from being prefixed with an ssh command.
        backup = rdiff_backup_wrapper.RdiffBackup(
            label='fake_backup',
            source_hostname='localhost',
            settings_path=None,
            command_runner=mock_command_runner)

        backup.include('/var')
        backup.exclude('/var/cache')
        backup.run()

        mock_command_runner.run.assert_called_once_with([
            '/fake/rdiff-backup', '--exclude', '/var/cache', '--include',
            '/var', '--exclude', '**', '/', '/fake/backup-store/fake_backup'
        ], False)
    def testRunCustomWorkflow_sshCompressionFlagTrue_sshCompressionNotDisabled(
            self):
        FLAGS.ssh_compression = True
        FLAGS.remote_user = '******'
        FLAGS.rdiff_backup_path = '/fake/rdiff-backup'
        FLAGS.backup_store_path = '/fake/backup-store'
        FLAGS.top_level_src_dir = '/'
        mock_command_runner = test_lib.GetMockCommandRunner()
        backup = rdiff_backup_wrapper.RdiffBackup(
            label='fake_backup',
            source_hostname='fake_host',
            settings_path=None,
            command_runner=mock_command_runner)

        backup.include('/fake_dir')
        backup.run()

        mock_command_runner.run.assert_called_once_with([
            '/fake/rdiff-backup', '--include', '/fake_dir', '--exclude', '**',
            'fake_user@fake_host::/', '/fake/backup-store/fake_backup'
        ], False)
 def testCheckRequiredFlags_backupStorePathNotSet_raisesException(self):
     FLAGS.backup_store_path = None
     with self.assertRaises(Exception):
         rdiff_backup_wrapper.RdiffBackup(label='unused',
                                          source_hostname='unused',
                                          settings_path=None)