Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions pgrepup/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
from ..helpers.database import *
from ..helpers.ui import *

ipv4_address = re.compile(
'^(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$'
)
ipv6_address = re.compile(
'^(?:(?:[0-9A-Fa-f]{1,4}:){6}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|::(?:[0-9A-Fa-f]{1,4}:){5}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){3}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){,2}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){2}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){,3}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}:(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){,4}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|(?:(?:[0-9A-Fa-f]{1,4}:){,6}[0-9A-Fa-f]{1,4})?::)$'
)

@dispatch.on('check')
def check(**kwargs):
Expand Down Expand Up @@ -249,13 +255,19 @@ def checks(target, single_test=None, db_conn=None):
if not rows:
continue

replication_rule = re.compile("^[ ]*host[ ]+replication[ ]+%s[ ]+%s/32[ ]+md5" % (
destination_host = get_connection_params('Destination')["host"]
if ipv4_address.match(destination_host):
destination_host += '/32'
if ipv6_address.match(destination_host):
destination_host += '/128'

replication_rule = re.compile("^[ ]*host[ ]+replication[ ]+%s[ ]+%s[ ]+md5" % (
get_pgrepup_replication_user(),
get_connection_params('Destination')["host"]
destination_host
))
connection_rule = re.compile("^[ ]*host[ ]+all[ ]+%s[ ]+%s/32[ ]+md5" % (
connection_rule = re.compile("^[ ]*host[ ]+all[ ]+%s[ ]+%s[ ]+md5" % (
get_pgrepup_replication_user(),
get_connection_params('Destination')["host"]
destination_host
))
replication_rule_present = False
connection_rule_present = False
Expand Down
2 changes: 1 addition & 1 deletion pgrepup/commands/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@dispatch.on('fix')
def fix():
def fix(**kwargs):

# Shortcut to ask master password before output Configuration message
decrypt(config().get('Source', 'password'))
Expand Down
34 changes: 17 additions & 17 deletions pgrepup/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@


@dispatch.on('setup')
def setup():

def setup(**kwargs):
result = True
if check_destination_subscriptions():
result = False
Expand Down Expand Up @@ -112,13 +111,15 @@ def _setup_source(conn, pg_pass):

pg_dumpall_schema = "%s/pg_dumpall_schema_%s.sql" % (get_tmp_folder(), uuid.uuid4().hex)
output_cli_message("Dump globals and schema of all databases")
pg_dumpall_schema_result = \
os.system('sh -c "PGPASSFILE=%(pgpass)s pg_dumpall -U %(user)s -h %(host)s -p%(port)s -s -f %(fname)s ' +
'--if-exists -c"' %
merge_two_dicts(
get_connection_params('Source'),
{"fname": pg_dumpall_schema, "pgpass": pg_pass}
))
sh_cmd = 'PGPASSFILE=%(pgpass)s pg_dumpall -U %(user)s -h %(host)s -p%(port)s -s -f %(fname)s --if-exists -c'
sh_cmd = sh_cmd % (
merge_two_dicts(
get_connection_params('Source'),
{"fname": pg_dumpall_schema, "pgpass": pg_pass}
)
)
sh_cmd = 'sh -c "%(sh_cmd)s"' % {'sh_cmd': sh_cmd}
pg_dumpall_schema_result = os.system(sh_cmd)
result['result'] = result['result'] and pg_dumpall_schema_result == 0
print(output_cli_result(result['result']))

Expand Down Expand Up @@ -158,14 +159,13 @@ def _setup_destination(conn, pg_pass, source_setup_results):
result = {'result': True}
output_cli_message("Create and import source globals and schema")
if 'pg_dumpall' in source_setup_results:
restore_schema_result = \
os.system(
'sh -c "PGPASSFILE=%(pgpass)s psql -U %(user)s -h %(host)s -p%(port)s -f %(fname)s -d postgres ' +
'>/dev/null 2>&1"'
% merge_two_dicts(
get_connection_params('Destination'),
{"fname": source_setup_results['pg_dumpall'], "pgpass": pg_pass}
))
sh_cmd = 'PGPASSFILE=%(pgpass)s psql -U %(user)s -h %(host)s -p%(port)s -f %(fname)s -d postgres >/dev/null 2>&1'
sh_cmd = sh_cmd % merge_two_dicts(
get_connection_params('Destination'),
{"fname": source_setup_results['pg_dumpall'], "pgpass": pg_pass}
)
sh_cmd = 'sh -c "%(sh_cmd)s"' % {'sh_cmd': sh_cmd}
restore_schema_result = os.system(sh_cmd)

result['result'] = result['result'] and restore_schema_result == 0
print(output_cli_result(restore_schema_result == 0))
Expand Down
2 changes: 1 addition & 1 deletion pgrepup/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


@dispatch.on('start')
def start():
def start(**kwargs):

# Shortcut to ask master password before output Configuration message
decrypt(config().get('Source', 'password'))
Expand Down
2 changes: 1 addition & 1 deletion pgrepup/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


@dispatch.on('status')
def status():
def status(**kwargs):
targets = ['Source', 'Destination']

# Shortcut to ask master password before output Configuration message
Expand Down
2 changes: 1 addition & 1 deletion pgrepup/commands/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@dispatch.on('stop')
def stop():
def stop(**kwargs):

# Shortcut to ask master password before output Configuration message
decrypt(config().get('Source', 'password'))
Expand Down
2 changes: 1 addition & 1 deletion pgrepup/commands/uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


@dispatch.on('uninstall')
def uninstall():
def uninstall(**kwargs):
stop()

output_cli_message("Uninstall operations", color='cyan')
Expand Down