Example #1
0
def bbpgsql_main(argv):
    cmd_name = basename(argv[0])
    dispatch_map = get_dispatch_map()
    if cmd_name in dispatch_map:
        options, args = non_destructive_minimal_parse_and_validate_args(argv)
        get_config_from_filename_and_set_up_logging(options.config_file)
        try:
            dispatch_map[cmd_name]()
        except Exception, e:
            get_logger().exception(str(e))
            logging.shutdown()
            stdout.write('\nERROR: %s' % str(e))
            exit(1)
Example #2
0
def restorewal_main():
    options, args = restorewal_handle_args()

    conf = get_config_from_filename_and_set_up_logging(options.config_file)

    repository = get_WAL_repository(conf)

    restorer = Restore_WAL(repository)
    restorer.restore(args[0], args[1])
 def test_write_config_to_filename(self):
     with TempDirectory() as d:
         config_filename = os.path.join(d.path, 'config.ini')
         write_config_to_filename(self.test_configuration, config_filename)
         config = get_config_from_filename_and_set_up_logging(
             config_filename
         )
         self.assertEqual('Test_value',
             config.get('Test Section', 'Test_key'))
Example #4
0
def archivewal_validate_options_and_args(options=None, args=None):
    args = args or []
    if not common_validate_options_and_args(options, args):
        return False
    config = get_config_from_filename_and_set_up_logging(options.config_file)
    if len(args) != 1 or not is_valid_file(config, args[0]):
        raise Exception('A relative path to a WAL file to be archived' \
                        ' must be provided!')
    return True
Example #5
0
def archivewal_main():
    options, args = archivewal_handle_args()

    conf = get_config_from_filename_and_set_up_logging(options.config_file)

    wal_filename_to_archive = get_wal_filename(conf, args[0])

    repository = get_WAL_repository(conf)

    commit_wal_to_repository(repository, wal_filename_to_archive)
Example #6
0
def storagestats_main():
    options, args = storagestats_handle_args()
    conf = get_config_from_filename_and_set_up_logging(options.config_file)
    repo_names = ['Snapshots', 'WAL Files']
    repositories = {
        repo_names[0]: get_Snapshot_repository(conf),
        repo_names[1]: get_WAL_repository(conf),
    }
    reporter = Storage_stats_reporter(repo_names, repositories)
    reporter.write_report(stdout)
Example #7
0
def archivepgsql_main():
    options, args = archivepgsql_handle_args()
    conf = get_config_from_filename_and_set_up_logging(options.config_file)
    data_dir = get_data_dir(conf)

    with TemporaryDirectory(suffix='archivepgsql') as tempdir:
        tag = generate_tag()
        archive_dst_path = join(tempdir, 'pgsql.snapshot.tar')
        repo = get_Snapshot_repository(conf)
        if options.dry_run:
            print("Dry Run")
            return
        else:
            perform_backup(data_dir, archive_dst_path, tag, repo)
Example #8
0
 def setup_config(self):
     self.config_path = os.path.join(self.tempdir.path, self.CONFIG_FILE)
     self.config_dict = {
         'General': {
             'pgsql_data_directory': self.data_dir,
         },
         'Snapshot': {
             'driver': 'memory',
         },
     }
     write_config_to_filename(self.config_dict, self.config_path)
     self.config = get_config_from_filename_and_set_up_logging(
         self.config_path
     )
 def write_config_to_disk(self):
     self.config_path = os.path.join(self.tempdir.path, self.CONFIG_FILE)
     write_config_to_filename(self.setup_config(), self.config_path)
     self.config = get_config_from_filename_and_set_up_logging(
         self.config_path
     )