run()

Main function, called by actual script in bin/, wraps all work done by script with the sole exception of reading and validating command line arguments.

These tasks (reading and validating arguments) are in this module, but they are called from OmniPITR::Program::new()

Name of called method should be self explanatory, and if you need further information - simply check doc for the method you have questions about.

do_some_removal()

Wraps all work necessary to remove obsolete WAL segments from archive.

Contains actual unlink calls, but all other work (checking pg_controldata, extracting last REDO segment, getting list of files to remove, calling pre-removal hook) is delegated to dedicated methods.

handle_pre_removal_processing()

Before removing obsolete WAL segment, omnipitr-restore can call arbitrary program to do whatever is necessary - for example - to send the WAL segment to backup server.

This is done in here. Each segment is first uncompressed to temporary directory, and then given program is called.

Temporary directory is always made so that it "looks" like it was called by archive-command from PostgreSQL, i.e.:

  • Current directory contains pg_xlog directory

  • Segment is unpacked

  • Segment is in pg_xlog directory

  • Handler program is called with segment name like 'pg_xlog/000000010000000500000073'

get_list_of_segments_to_remove()

Scans source directory, and returns names of all files, which are "older" than last required segment (REDO segment from pg_controldata).

Older - is defined as alphabetically smaller than REDO segment.

Returns at most X files, where X is defined by --remove-at-a-time command line option.

get_last_redo_segment()

Based on information from pg_controldata, returns name of file that contains oldest file required in case recovery would have to be restarted.

This is required to be able to tell which files can be safely removed from archive.

get_control_data()

Wraps SUPER::get_control_data in such way that it will not die in case of problems.

Reason: errors with parsin pg_controldata cannot cause die from omnipitr-restore, to avoid bringing PostgreSQL from WAL-slave to Standalone.

try_to_restore_and_exit()

Checks if requested wal segment exists, and is ready to be restored ( vide --recovery-delay option).

Handles also situations where there is finish request (both immediate and smart).

If recovery worked - finished with status 0.

If no file can be returned yet - goes back to main loop in run() method.

copy_segment_to()

Helper function which deals with copying segment from archive to given destination, handling compression when necessary.

check_for_trigger_file()

Checks existence and possibly content of finish-trigger file, setting appropriate flags.

read_args_specification

Defines which options are legal for this program.

read_args_normalization

Function called back from OmniPITR::Program::read_args(), with parsed args as hashref.

Is responsible for putting arguments to correct places, initializing logs, and so on.

validate_args()

Does all necessary validation of given command line arguments.

One exception is for compression programs paths - technically, it could be validated in here, but benefit would be pretty limited, and code to do so relatively complex, as compression program path might, but doesn't have to be actual file path - it might be just program name (without path), which is the default.