IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40951


Ignore:
Timestamp:
Oct 18, 2019, 2:55:33 PM (7 years ago)
Author:
fairlamb
Message:

Added a test for checking 'delete-after' args given to rsync

Location:
branches/ipp-259_genericise_backups/tools/backups
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ipp-259_genericise_backups/tools/backups/backup_test.py

    r40949 r40951  
    88import backups.utils.errors as errs
    99from backups.backup import Backup
    10 from backups.utils.config_parse_helper import ConfigSchema
     10from backups.utils.config_parse_helper import ConfigSchema, ConfigSchemaSection, ConfigSchemaLine
    1111
    1212TEST_DEFAULT_CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'testing/backup_test.config')
     
    486486            backy._run_rsync()
    487487
    488     def test_rsync_requires_dash_r_arg_for_copying_dirs(self, tmpdir):
     488    def test_rsync_requires_dash_r_arg_for_copying_only_dirs(self, tmpdir):
    489489        config = make_default_config(tmpdir, ['bck1', 'bck2'])
    490490        source = os.path.join(tmpdir, "some_dir")
     
    521521        assert os.path.exists(expected1dir)
    522522        assert os.path.exists(expected2dir)
     523
     524    def test_rsync_with_delete_after_options(self, tmpdir):
     525        config = make_default_config(tmpdir, ['bck1', 'bck2'])
     526        source_dir = os.path.join(tmpdir, "some_dir")
     527        source_file1 = os.path.join(source_dir, "file1")
     528        source_file2 = os.path.join(source_dir, "file2")
     529        source_file3 = os.path.join(source_dir, "file3")
     530        config['RSYNC'] = \
     531        { 'sources' : f"{source_dir}"
     532        , 'additional_args' : "-v -z -r --progress"
     533        }
     534
     535        os.makedirs(source_dir)
     536        Path(source_file1).touch()
     537        Path(source_file2).touch()
     538        Path(source_file3).touch()
     539
     540        schema = ConfigSchema(None)
     541        schema.add_section(bckup.DEFAULT_SCHEMA_SECTION)
     542        schema.add_section(bckup.RSYNC_SCHEMA_SECTION)
     543
     544        backy = Backup(config, schema)
     545
     546        expected1dir  = os.path.join(tmpdir, 'bck1', 'some_dir', 'file1')
     547        expected2dir  = os.path.join(tmpdir, 'bck1', 'some_dir', 'file2')
     548        expected3dir  = os.path.join(tmpdir, 'bck1', 'some_dir', 'file3')
     549        assert not os.path.exists(expected1dir)
     550        assert not os.path.exists(expected2dir)
     551        assert not os.path.exists(expected3dir)
     552        backy._run_rsync()
     553        print(expected1dir)
     554        assert os.path.exists(expected1dir)
     555        assert os.path.exists(expected2dir)
     556        assert os.path.exists(expected3dir)
     557
     558        # Delete two files, create a new one.
     559        os.remove(source_file2)
     560        os.remove(source_file3)
     561        source_file4 = os.path.join(source_dir, "file4")
     562        Path(source_file4).touch()
     563        expected4dir = os.path.join(tmpdir, 'bck1', 'some_dir', 'file4')
     564
     565        # Rsync will add 4, and 2 and 3 should still exist
     566        backy._run_rsync()
     567        assert os.path.exists(expected1dir)
     568        assert os.path.exists(expected2dir)
     569        assert os.path.exists(expected3dir)
     570        assert os.path.exists(expected4dir)
     571
     572        # with delete after option removed files are cleaned up
     573        config['RSYNC'] = \
     574        { 'sources' : f"{source_dir}"
     575        , 'additional_args' : '-v -z -r --delete-after'
     576        }
     577        backy = Backup(config, schema)
     578        backy._run_rsync()
     579        assert os.path.exists(expected1dir)
     580        assert not os.path.exists(expected2dir)
     581        assert not os.path.exists(expected3dir)
     582        assert os.path.exists(expected4dir)
     583
    523584
    524585
  • branches/ipp-259_genericise_backups/tools/backups/confluence_backup.py

    r40950 r40951  
    9393
    9494def main():
    95     jb = ConfluenceBackup()
    96     jb.run_backup()
     95    cb = ConfluenceBackup()
     96    cb.run_backup()
    9797
    9898
Note: See TracChangeset for help on using the changeset viewer.