IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41067 for trunk/backups


Ignore:
Timestamp:
Nov 5, 2019, 3:18:35 PM (7 years ago)
Author:
fairlamb
Message:

merge of branch ipp-350 into trunk

Location:
trunk/backups
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/backups

  • trunk/backups/backup.py

    r40973 r41067  
    3333    [ ConfigSchemaLine('sources', True, list, SpecialSchemaProcessing.commma_separated)
    3434    , ConfigSchemaLine('additional_args', False, list, SpecialSchemaProcessing.space_separated)
     35    , ConfigSchemaLine('sub-dirs', False, list, SpecialSchemaProcessing.commma_separated)
    3536    ]
    3637)
     
    8384
    8485        self.read_config_and_schema(config, schema)
    85         # self.read_copy_config_section(config, schema)
    86         # self.read_tar_config_section(config, schema)
    87         # self.read_rsync_config_section(config, schema)
    88         # self.read_mysqldump_config_section(config, schema)
    8986
    9087    def read_config_and_schema(self, config: ConfigParser, schema: ConfigSchema):
     
    206203        self.target_backup_paths_ok(raise_error=True)
    207204        backup_paths = self.default_dict['backup_paths']
    208         for bp in backup_paths:
    209             # if not path.exists(bp):
    210             #     raise errs.ValidationError(f"ValidationError: target path does not exist: {bp}")
    211 
    212             for s in self.rsync_dict['sources']:
    213                 if not path.exists(s):
    214                     raise errs.ValidationError(f"ValidationError: target path does not exist: {s}")
     205
     206        sources = self.rsync_dict['sources']
     207        for i in range(0, len(sources)):
     208            source = sources[i]
     209            if not path.exists(source):
     210                    raise errs.ValidationError(f"ValidationError: target path does not exist: {source}")
     211
     212            for bp in backup_paths:
    215213                try:
    216                     args = [s, bp]
     214                    additional_args = []
    217215                    if 'additional_args' in self.rsync_dict.keys():
    218                         args = args + self.rsync_dict['additional_args']
     216                        additional_args = self.rsync_dict['additional_args']
     217
     218                    source_and_target_args = [source, bp]
     219
     220                    # sub-dirs option allows items to be backed up to subdirs within
     221                    # the source for better naming
     222                    if 'sub-dirs' in self.rsync_dict:
     223                        sub_dirs = self.rsync_dict['sub-dirs']
     224                        if len(sub_dirs) != len(sources):
     225                            raise errs.ValidationError(f"ValidationError: if using " +
     226                                "subdirs the number of subdirs must equal the number of sources")
     227                        bp_with_subdir = os.path.join(bp, sub_dirs[i])
     228                        if not os.path.exists(bp_with_subdir):
     229                            os.makedirs(bp_with_subdir)
     230                        source_and_target_args = [source, bp_with_subdir]
     231
     232                    args = source_and_target_args + additional_args
    219233                    sub_utils.local_rsync_wrapper(args)
     234
    220235                except errs.SubprocessError as e:
    221236                    raise errs.SubprocessError( f"Error: rsync\n"
    222                                                 f"    from: {s}\n"
    223                                                 f"    to: {bp}\n"
     237                                                f"    from: {source_and_target_args[0]}\n"
     238                                                f"    to: {source_and_target_args[1]}\n"
    224239                                              ) from e
    225240        return 0
  • trunk/backups/backup_test.py

    r40967 r41067  
    596596        assert os.path.exists(expected4dir)
    597597
     598    def test_rsync_with_subdirs_option(self, tmpdir):
     599        config = make_default_config(tmpdir, ['bck1', 'bck2'])
     600        source1 = os.path.join(tmpdir, "some_dir")
     601        source2 = os.path.join(tmpdir, "some_other_dir")
     602        file_in_dir = os.path.join(source1, "and_specific_file.jpeg")
     603        file_in_other_dir = os.path.join(source2, "another_file.jpeg")
     604        os.makedirs(source1)
     605        os.makedirs(source2)
     606        Path(file_in_dir).touch()
     607        Path(file_in_other_dir).touch()
     608
     609        config['RSYNC'] = \
     610        { 'sources' : f"{source1}, {source2}"
     611        , 'additional_args' : "-a --progress -v"
     612        , 'sub-dirs' : "subdir_with_better_name1, subdir_with_better_name2"
     613        }
     614
     615        schema = ConfigSchema(None)
     616        schema.add_section(bckup.DEFAULT_SCHEMA_SECTION)
     617        schema.add_section(bckup.RSYNC_SCHEMA_SECTION)
     618
     619        backy = Backup(config, schema)
     620
     621        expected_bak1_src1_dir  = os.path.join(tmpdir, 'bck1', 'subdir_with_better_name1', 'some_dir')
     622        expected_bak1_src1_file = os.path.join(tmpdir, 'bck1', 'subdir_with_better_name1', 'some_dir', 'and_specific_file.jpeg')
     623        expected_bak1_src2_dir  = os.path.join(tmpdir, 'bck1', 'subdir_with_better_name2', 'some_other_dir')
     624        expected_bak1_src2_file = os.path.join(tmpdir, 'bck1', 'subdir_with_better_name2', 'some_other_dir', 'another_file.jpeg')
     625        expected_bak2_src1_dir  = os.path.join(tmpdir, 'bck2', 'subdir_with_better_name1', 'some_dir')
     626        expected_bak2_src1_file = os.path.join(tmpdir, 'bck2', 'subdir_with_better_name1', 'some_dir', 'and_specific_file.jpeg')
     627        expected_bak2_src2_dir  = os.path.join(tmpdir, 'bck2', 'subdir_with_better_name2', 'some_other_dir')
     628        expected_bak2_src2_file = os.path.join(tmpdir, 'bck2', 'subdir_with_better_name2', 'some_other_dir', 'another_file.jpeg')
     629        assert not os.path.exists(expected_bak1_src1_dir)
     630        assert not os.path.exists(expected_bak1_src1_file)
     631        assert not os.path.exists(expected_bak1_src2_dir)
     632        assert not os.path.exists(expected_bak1_src2_file)
     633        assert not os.path.exists(expected_bak2_src1_dir)
     634        assert not os.path.exists(expected_bak2_src1_file)
     635        assert not os.path.exists(expected_bak2_src2_dir)
     636        assert not os.path.exists(expected_bak2_src2_file)
     637        backy._run_rsync()
     638        assert os.path.exists(expected_bak1_src1_dir)
     639        assert os.path.exists(expected_bak1_src1_file)
     640        assert os.path.exists(expected_bak1_src2_dir)
     641        assert os.path.exists(expected_bak1_src2_file)
     642        assert os.path.exists(expected_bak2_src1_dir)
     643        assert os.path.exists(expected_bak2_src1_file)
     644        assert os.path.exists(expected_bak2_src2_dir)
     645        assert os.path.exists(expected_bak2_src2_file)
    598646
    599647@pytest.mark.skip(reason="Requires a fake database to be setup")
  • trunk/backups/confluence_backup.py

    r40967 r41067  
    3232        , ConfigSchemaLine('target_filename', True,  str)
    3333        , ConfigSchemaLine('prefix_date',     True,  bool)
     34        ])
     35    , ConfigSchemaSection('RSYNC',
     36        [ ConfigSchemaLine('sources', True, list,
     37            cfg_help.SpecialSchemaProcessing.commma_separated)
     38        , ConfigSchemaLine('additional_args', False, list,
     39            cfg_help.SpecialSchemaProcessing.space_separated)
     40        , ConfigSchemaLine('sub-dirs', False, list,
     41            cfg_help.SpecialSchemaProcessing.commma_separated)
    3442        ])
    3543    , ConfigSchemaSection('MYSQLDUMP',
  • trunk/backups/confluence_backup_test.py

    r40967 r41067  
    3434        , 'target_filename' : 'confluence.tar.gz'
    3535        , 'prefix_date' : 'True'
     36        }
     37    config['RSYNC'] = \
     38        { 'sources' : (f"{os.path.join(tmpdir, 'rsync_source_dir1')},"
     39                       f"{os.path.join(tmpdir, 'rsync_source_dir2')}")
     40        , 'additional_args' : '-a --delete-after --exclude exclude_me_if_you_like'
     41        , 'sub-dirs' : 'conf_subdir1, conf_subdir2'
    3642        }
    3743    config['MYSQLDUMP'] = \
     
    8288    assert os.path.exists(confluence_attachment_2_filepath)
    8389
     90    # Create a few folders to be rsync'd
     91    rsync_source_dir1 = os.path.join(tmpdir, "rsync_source_dir1")
     92    rsync_source_dir2 = os.path.join(tmpdir, "rsync_source_dir2")
     93    file_in_rsync_dir1 = os.path.join(rsync_source_dir1, "some_file_to_rsync")
     94    file_in_rsync_dir2 = os.path.join(rsync_source_dir2, "some_other_file_to_rsync")
     95    exluded_file = os.path.join(rsync_source_dir1, "exclude_me_if_you_like")
     96    os.makedirs(rsync_source_dir1)
     97    os.makedirs(rsync_source_dir2)
     98    Path(file_in_rsync_dir1).touch()
     99    Path(file_in_rsync_dir2).touch()
     100    Path(exluded_file).touch()
     101    assert os.path.exists(file_in_rsync_dir1)
     102    assert os.path.exists(file_in_rsync_dir2)
     103    assert os.path.exists(exluded_file)
     104
    84105
    85106class TestArguments(object):
     
    287308        assert os.path.exists(expected_confluence_bak1_tar)
    288309        assert os.path.exists(expected_confluence_bak2_tar)
     310
     311
     312class TestRsyncOfFiles(object):
     313
     314    def test_confluence_rsync_with_subdirs(self, tmpdir):
     315        """This should be similar to the regular Backup version"""
     316        create_items_for_full_confluence_backup_test(tmpdir)
     317        config = make_config(tmpdir)
     318
     319        cb = ConfluenceBackup(config_file=config)
     320
     321        # Expected resulting rsync directories
     322        expected_confluence_host_rsync1 = os.path.join(tmpdir, "host_backup_path", "conf_subdir1", "rsync_source_dir1")
     323        expected_confluence_bak1_rsync1 = os.path.join(tmpdir, "backup_1_path",    "conf_subdir1", "rsync_source_dir1")
     324        expected_confluence_bak2_rsync1 = os.path.join(tmpdir, "backup_2_path",    "conf_subdir1", "rsync_source_dir1")
     325        expected_confluence_host_rsync2 = os.path.join(tmpdir, "host_backup_path", "conf_subdir2", "rsync_source_dir2")
     326        expected_confluence_bak1_rsync2 = os.path.join(tmpdir, "backup_1_path",    "conf_subdir2", "rsync_source_dir2")
     327        expected_confluence_bak2_rsync2 = os.path.join(tmpdir, "backup_2_path",    "conf_subdir2", "rsync_source_dir2")
     328        assert not os.path.exists(expected_confluence_host_rsync1)
     329        assert not os.path.exists(expected_confluence_bak1_rsync1)
     330        assert not os.path.exists(expected_confluence_bak2_rsync1)
     331        assert not os.path.exists(expected_confluence_host_rsync2)
     332        assert not os.path.exists(expected_confluence_bak1_rsync2)
     333        assert not os.path.exists(expected_confluence_bak2_rsync2)
     334        # Expected resulting rsync files
     335        expected_file_host_dir1 = os.path.join( expected_confluence_host_rsync1, "some_file_to_rsync")
     336        expected_file_bak1_dir1 = os.path.join( expected_confluence_bak1_rsync1, "some_file_to_rsync")
     337        expected_file_bak2_dir1 = os.path.join( expected_confluence_bak2_rsync1, "some_file_to_rsync")
     338        expected_file_host_dir2 = os.path.join( expected_confluence_host_rsync2, "some_other_file_to_rsync")
     339        expected_file_bak1_dir2 = os.path.join( expected_confluence_bak1_rsync2, "some_other_file_to_rsync")
     340        expected_file_bak2_dir2 = os.path.join( expected_confluence_bak2_rsync2, "some_other_file_to_rsync")
     341        assert not os.path.exists(expected_file_host_dir1)
     342        assert not os.path.exists(expected_file_bak1_dir1)
     343        assert not os.path.exists(expected_file_bak2_dir1)
     344        assert not os.path.exists(expected_file_host_dir2)
     345        assert not os.path.exists(expected_file_bak1_dir2)
     346        assert not os.path.exists(expected_file_bak2_dir2)
     347        an_excluded_file = os.path.join(expected_confluence_host_rsync1, "exclude_me_if_you_like")
     348        assert not os.path.exists(an_excluded_file)
     349
     350        rsync_result = cb._run_rsync()
     351        assert rsync_result == 0
     352
     353        # All files Rsync'd
     354        assert os.path.exists(expected_confluence_host_rsync1)
     355        assert os.path.exists(expected_confluence_bak1_rsync1)
     356        assert os.path.exists(expected_confluence_bak2_rsync1)
     357        assert os.path.exists(expected_confluence_host_rsync2)
     358        assert os.path.exists(expected_confluence_bak1_rsync2)
     359        assert os.path.exists(expected_confluence_bak2_rsync2)
     360        assert os.path.exists(expected_file_host_dir1)
     361        assert os.path.exists(expected_file_bak1_dir1)
     362        assert os.path.exists(expected_file_bak2_dir1)
     363        assert os.path.exists(expected_file_host_dir2)
     364        assert os.path.exists(expected_file_bak1_dir2)
     365        assert os.path.exists(expected_file_bak2_dir2)
     366        assert not os.path.exists(an_excluded_file)
  • trunk/backups/jira_backup.py

    r40967 r41067  
    3232        , ConfigSchemaLine('target_filename', True,  str)
    3333        , ConfigSchemaLine('prefix_date',     True,  bool)
     34        ])
     35    , ConfigSchemaSection('RSYNC',
     36        [ ConfigSchemaLine('sources', True, list,
     37            cfg_help.SpecialSchemaProcessing.commma_separated)
     38        , ConfigSchemaLine('additional_args', False, list,
     39            cfg_help.SpecialSchemaProcessing.space_separated)
     40        , ConfigSchemaLine('sub-dirs', False, list,
     41            cfg_help.SpecialSchemaProcessing.commma_separated)
    3442        ])
    3543    , ConfigSchemaSection('MYSQLDUMP',
  • trunk/backups/jira_backup_test.py

    r40967 r41067  
    3333        , 'target_filename' : 'jira.tar.gz'
    3434        , 'prefix_date' : 'True'
     35        }
     36    config['RSYNC'] = \
     37        { 'sources' : (f"{os.path.join(tmpdir, 'rsync_source_dir1')},"
     38                       f"{os.path.join(tmpdir, 'rsync_source_dir2')}")
     39        , 'additional_args' : '-a --delete-after'
     40        , 'sub-dirs' : 'jira_subdir1, jira_subdir2'
    3541        }
    3642    config['MYSQLDUMP'] = \
     
    8187    assert os.path.exists(jira_attachment_2_filepath)
    8288
     89    # Create a few folders to be rsync'd
     90    rsync_source_dir1 = os.path.join(tmpdir, "rsync_source_dir1")
     91    rsync_source_dir2 = os.path.join(tmpdir, "rsync_source_dir2")
     92    file_in_rsync_dir1 = os.path.join(rsync_source_dir1, "some_file_to_rsync")
     93    file_in_rsync_dir2 = os.path.join(rsync_source_dir2, "some_other_file_to_rsync")
     94    os.makedirs(rsync_source_dir1)
     95    os.makedirs(rsync_source_dir2)
     96    Path(file_in_rsync_dir1).touch()
     97    Path(file_in_rsync_dir2).touch()
     98    assert os.path.exists(file_in_rsync_dir1)
     99    assert os.path.exists(file_in_rsync_dir2)
     100
    83101
    84102class TestArguments(object):
     
    288306        assert os.path.exists(expected_jira_bak1_tar)
    289307        assert os.path.exists(expected_jira_bak2_tar)
     308
     309
     310class TestRsyncOfFiles(object):
     311
     312    def test_jira_rsync_with_subdirs(self, tmpdir):
     313        """This should be similar to the regular Backup version"""
     314        create_items_for_full_jira_backup_test(tmpdir)
     315        config = make_config(tmpdir)
     316
     317        jb = JiraBackup(config_file=config)
     318
     319        # Expected resulting rsync directories
     320        expected_jira_host_rsync1 = os.path.join(tmpdir, "host_backup_path", "jira_subdir1", "rsync_source_dir1")
     321        expected_jira_bak1_rsync1 = os.path.join(tmpdir, "backup_1_path",    "jira_subdir1", "rsync_source_dir1")
     322        expected_jira_bak2_rsync1 = os.path.join(tmpdir, "backup_2_path",    "jira_subdir1", "rsync_source_dir1")
     323        expected_jira_host_rsync2 = os.path.join(tmpdir, "host_backup_path", "jira_subdir2", "rsync_source_dir2")
     324        expected_jira_bak1_rsync2 = os.path.join(tmpdir, "backup_1_path",    "jira_subdir2", "rsync_source_dir2")
     325        expected_jira_bak2_rsync2 = os.path.join(tmpdir, "backup_2_path",    "jira_subdir2", "rsync_source_dir2")
     326        assert not os.path.exists(expected_jira_host_rsync1)
     327        assert not os.path.exists(expected_jira_bak1_rsync1)
     328        assert not os.path.exists(expected_jira_bak2_rsync1)
     329        assert not os.path.exists(expected_jira_host_rsync2)
     330        assert not os.path.exists(expected_jira_bak1_rsync2)
     331        assert not os.path.exists(expected_jira_bak2_rsync2)
     332        # Expected resulting rsync files
     333        expected_file_host_dir1 = os.path.join( expected_jira_host_rsync1, "some_file_to_rsync")
     334        expected_file_bak1_dir1 = os.path.join( expected_jira_bak1_rsync1, "some_file_to_rsync")
     335        expected_file_bak2_dir1 = os.path.join( expected_jira_bak2_rsync1, "some_file_to_rsync")
     336        expected_file_host_dir2 = os.path.join( expected_jira_host_rsync2, "some_other_file_to_rsync")
     337        expected_file_bak1_dir2 = os.path.join( expected_jira_bak1_rsync2, "some_other_file_to_rsync")
     338        expected_file_bak2_dir2 = os.path.join( expected_jira_bak2_rsync2, "some_other_file_to_rsync")
     339        assert not os.path.exists(expected_file_host_dir1)
     340        assert not os.path.exists(expected_file_bak1_dir1)
     341        assert not os.path.exists(expected_file_bak2_dir1)
     342        assert not os.path.exists(expected_file_host_dir2)
     343        assert not os.path.exists(expected_file_bak1_dir2)
     344        assert not os.path.exists(expected_file_bak2_dir2)
     345
     346        rsync_result = jb._run_rsync()
     347        assert rsync_result == 0
     348
     349        # All files Rsync'd
     350        assert os.path.exists(expected_jira_host_rsync1)
     351        assert os.path.exists(expected_jira_bak1_rsync1)
     352        assert os.path.exists(expected_jira_bak2_rsync1)
     353        assert os.path.exists(expected_jira_host_rsync2)
     354        assert os.path.exists(expected_jira_bak1_rsync2)
     355        assert os.path.exists(expected_jira_bak2_rsync2)
     356        assert os.path.exists(expected_file_host_dir1)
     357        assert os.path.exists(expected_file_bak1_dir1)
     358        assert os.path.exists(expected_file_bak2_dir1)
     359        assert os.path.exists(expected_file_host_dir2)
     360        assert os.path.exists(expected_file_bak1_dir2)
     361        assert os.path.exists(expected_file_bak2_dir2)
  • trunk/backups/testing/confluence_test.config

    r40967 r41067  
    1717prefix_date = True
    1818
     19[RSYNC]
     20sources = /opt/atlassian, /var/atlassian
     21additional_args = -a --delete-after
     22sub-dirs = conf-install, conf-home
     23
    1924[MYSQLDUMP]
    2025user = dumper
  • trunk/backups/testing/jira_test.config

    r40967 r41067  
    1616prefix_date = True
    1717
     18[RSYNC]
     19sources = /opt/atlassian, /var/atlassian
     20additional_args = -a --delete-after
     21sub-dirs = jira-install, jira-home
     22
    1823[MYSQLDUMP]
    1924user = dumper
Note: See TracChangeset for help on using the changeset viewer.