Skip to content

Commit

Permalink
Added --backup-ssh-port and --db-ssh-port options to support non-defa…
Browse files Browse the repository at this point in the history
…ult SSH ports.

Contributed by Cynthia Shang.
  • Loading branch information
cmwshang authored and dwsteele committed Aug 1, 2017
1 parent fa99243 commit ce2b18c
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 16 deletions.
18 changes: 18 additions & 0 deletions doc/xml/reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@
<example>backrest</example>
</config-key>

<!-- CONFIG - REPO SECTION - BACKUP-SSH-PORT KEY -->
<config-key id="backup-ssh-port" name="Backup SSH Port">
<summary>Backup server SSH port when <setting>backup-host</setting> is set.</summary>

<text>Use this option to specify a non-default SSH port for the backup server.</text>

<example>25</example>
</config-key>

<!-- CONFIG - REPO SECTION - REPO-PATH KEY -->
<config-key id="repo-path" name="Repository Path">
<summary>Repository path where WAL segments and backups stored.</summary>
Expand Down Expand Up @@ -685,6 +694,15 @@

<example>/var/run/postgresql</example>
</config-key>

<!-- CONFIG - STANZA SECTION - DB-SSH-PORT KEY -->
<config-key id="db-ssh-port" name="Database SSH Port">
<summary>Database server SSH port when <setting>db-host</setting> is set.</summary>

<text>Use this option to specify a non-default SSH port for a database server.</text>

<example>25</example>
</config-key>
</config-key-list>
</config-section>
</config-section-list>
Expand Down
8 changes: 8 additions & 0 deletions doc/xml/release.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@

<p>Modified the <cmd>info</cmd> command (both text and JSON output) to display the archive ID and minimum/maximum WAL currently present in the archive for the current and prior, if any, database cluster version.</p>
</release-item>

<release-item>
<release-item-contributor-list>
<release-item-contributor id="shang.cynthia"/>
</release-item-contributor-list>

<p>Added <br-option>--backup-ssh-port</br-option> and <br-option>--db-ssh-port</br-option> options to support non-default SSH ports.</p>
</release-item>
</release-feature-list>

<release-refactor-list>
Expand Down
30 changes: 30 additions & 0 deletions lib/pgBackRest/Config/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ use constant OPTION_BACKUP_CONFIG => 'backup-c
push @EXPORT, qw(OPTION_BACKUP_CONFIG);
use constant OPTION_BACKUP_HOST => 'backup-host';
push @EXPORT, qw(OPTION_BACKUP_HOST);
use constant OPTION_BACKUP_SSH_PORT => 'backup-ssh-port';
push @EXPORT, qw(OPTION_BACKUP_SSH_PORT);
use constant OPTION_BACKUP_STANDBY => 'backup-standby';
push @EXPORT, qw(OPTION_BACKUP_STANDBY);
use constant OPTION_BACKUP_USER => 'backup-user';
Expand Down Expand Up @@ -410,11 +412,14 @@ use constant OPTION_DB_PATH => OPTION_PR
push @EXPORT, qw(OPTION_DB_PATH);
use constant OPTION_DB_PORT => OPTION_PREFIX_DB . '-port';
push @EXPORT, qw(OPTION_DB_PORT);
use constant OPTION_DB_SSH_PORT => OPTION_PREFIX_DB . '-ssh-port';
push @EXPORT, qw(OPTION_DB_SSH_PORT);
use constant OPTION_DB_SOCKET_PATH => OPTION_PREFIX_DB . '-socket-path';
push @EXPORT, qw(OPTION_DB_SOCKET_PATH);
use constant OPTION_DB_USER => OPTION_PREFIX_DB . '-user';
push @EXPORT, qw(OPTION_DB_USER);


####################################################################################################################################
# Option Defaults
####################################################################################################################################
Expand Down Expand Up @@ -1659,6 +1664,18 @@ my %oOptionRule =
},
},

&OPTION_BACKUP_SSH_PORT =>
{
&OPTION_RULE_SECTION => CONFIG_SECTION_GLOBAL,
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
&OPTION_RULE_REQUIRED => false,
&OPTION_RULE_COMMAND => OPTION_BACKUP_HOST,
&OPTION_RULE_DEPEND =>
{
&OPTION_RULE_DEPEND_OPTION => OPTION_BACKUP_HOST
}
},

&OPTION_BACKUP_STANDBY =>
{
&OPTION_RULE_SECTION => CONFIG_SECTION_GLOBAL,
Expand Down Expand Up @@ -2036,6 +2053,19 @@ my %oOptionRule =
}
},

&OPTION_DB_SSH_PORT =>
{
&OPTION_RULE_SECTION => CONFIG_SECTION_STANZA,
&OPTION_RULE_PREFIX => OPTION_PREFIX_DB,
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
&OPTION_RULE_REQUIRED => false,
&OPTION_RULE_COMMAND => OPTION_DB_HOST,
&OPTION_RULE_DEPEND =>
{
&OPTION_RULE_DEPEND_OPTION => OPTION_DB_HOST
},
},

&OPTION_DB_USER =>
{
&OPTION_RULE_SECTION => CONFIG_SECTION_STANZA,
Expand Down
3 changes: 3 additions & 0 deletions lib/pgBackRest/Protocol/Helper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,15 @@ sub protocolGet
my $strOptionUser = OPTION_BACKUP_USER;
my $strOptionDbPort = undef;
my $strOptionDbSocketPath = undef;
my $strOptionSshPort = OPTION_BACKUP_SSH_PORT;

if ($strRemoteType eq DB)
{
$strOptionCmd = optionIndex(OPTION_DB_CMD, $iRemoteIdx);
$strOptionConfig = optionIndex(OPTION_DB_CONFIG, $iRemoteIdx);
$strOptionHost = optionIndex(OPTION_DB_HOST, $iRemoteIdx);
$strOptionUser = optionIndex(OPTION_DB_USER, $iRemoteIdx);
$strOptionSshPort = optionIndex(OPTION_DB_SSH_PORT, $iRemoteIdx);
}

# Db socket is not valid in all contexts (restore, for instance)
Expand Down Expand Up @@ -264,6 +266,7 @@ sub protocolGet
optionGet(OPTION_COMPRESS_LEVEL_NETWORK),
optionGet($strOptionHost),
optionGet($strOptionUser),
optionGet($strOptionSshPort, false),
optionGet(OPTION_PROTOCOL_TIMEOUT)
);

Expand Down
11 changes: 8 additions & 3 deletions lib/pgBackRest/Protocol/Remote/Master.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ sub new
$iCompressLevelNetwork, # Set compression level for network only compression
$strHost, # Host to connect to for remote (optional as this can also be used for local)
$strUser, # User to connect to for remote (must be set if strHost is set)
$iProtocolTimeout # Protocol timeout
$iSshPort, # Specified if other than default port is needed for ssh
$iProtocolTimeout, # Protocol timeout
) =
logDebugParam
(
Expand All @@ -44,12 +45,16 @@ sub new
{name => 'iCompressLevelNetwork'},
{name => 'strHost'},
{name => 'strUser'},
{name => 'iProtocolTimeout'}
{name => 'iSshPort', required => false},
{name => 'iProtocolTimeout'},
);

my $strCommandSshPort = defined($iSshPort) ? '-p ' . $iSshPort . ' ' : '';

# Create SSH command
$strCommand =
"${strCommandSSH} -o LogLevel=error -o Compression=no -o PasswordAuthentication=no ${strUser}\@${strHost} '${strCommand}'";
"${strCommandSSH} -o LogLevel=error -o Compression=no -o PasswordAuthentication=no $strCommandSshPort" .
"${strUser}\@${strHost} '${strCommand}'";

# Init object and store variables
my $self = $class->SUPER::new(
Expand Down
Loading

0 comments on commit ce2b18c

Please sign in to comment.