Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ timeline id in clone section for Spilo #760

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions postgres-appliance/bootstrap/clone_with_wale.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ def read_configuration():
dest='recovery_target_time_string')
parser.add_argument('--dry-run', action='store_true', help='find a matching backup and build the wal-e '
'command to fetch that backup without running it')
parser.add_argument('--recovery-target-timeline',
help='the timeline from which recovery will proceed')
args = parser.parse_args()

options = namedtuple('Options', 'name datadir recovery_target_time dry_run')
options = namedtuple('Options', 'name datadir recovery_target_time recovery_target_timeline dry_run')
if args.recovery_target_time_string:
recovery_target_time = parse(args.recovery_target_time_string)
if recovery_target_time.tzinfo is None:
raise Exception("recovery target time must contain a timezone")
else:
recovery_target_time = None

return options(args.scope, args.datadir, recovery_target_time, args.dry_run)
return options(args.scope, args.datadir, recovery_target_time, args.recovery_target_timeline, args.dry_run)


def build_wale_command(command, datadir=None, backup=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def build_wale_command(command, datadir=None, backup=None):
def build_wale_command(command, datadir=None, backup=None):

Expand Down Expand Up @@ -65,7 +67,7 @@ def fix_output(output):
yield '\t'.join(line.split())


def choose_backup(backup_list, recovery_target_time):
def choose_backup(backup_list, recovery_target_time, recovery_target_timeline):
hughcapet marked this conversation as resolved.
Show resolved Hide resolved
""" pick up the latest backup file starting before time recovery_target_time"""

match_timestamp = match = None
Expand Down Expand Up @@ -140,7 +142,7 @@ def get_wale_environments(env):
yield name, orig_value


def find_backup(recovery_target_time, env):
def find_backup(recovery_target_time, recovery_target_timeline, env):
old_value = None
for name, value in get_wale_environments(env):
logger.info('Trying %s for clone', value)
Expand All @@ -150,7 +152,7 @@ def find_backup(recovery_target_time, env):
backup_list = list_backups(env)
if backup_list:
if recovery_target_time:
backup = choose_backup(backup_list, recovery_target_time)
backup = choose_backup(backup_list, recovery_target_time, recovery_target_timeline)
if backup:
return backup, (name if value != old_value else None)
else: # We assume that the LATEST backup will be for the biggest postgres version!
Expand All @@ -163,7 +165,7 @@ def find_backup(recovery_target_time, env):
def run_clone_from_s3(options):
env = os.environ.copy()

backup_name, update_envdir = find_backup(options.recovery_target_time, env)
backup_name, update_envdir = find_backup(options.recovery_target_time, options.recovery_target_timeline, env)

backup_fetch_cmd = build_wale_command('backup-fetch', options.datadir, backup_name)
logger.info("cloning cluster %s using %s", options.name, ' '.join(backup_fetch_cmd))
Expand Down
2 changes: 1 addition & 1 deletion postgres-appliance/scripts/configure_spilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def deep_update(a, b):
method: clone_with_wale
clone_with_wale:
command: envdir "{{CLONE_WALE_ENV_DIR}}" python3 /scripts/clone_with_wale.py
--recovery-target-time="{{CLONE_TARGET_TIME}}"
--recovery-target-time="{{CLONE_TARGET_TIME}}" --recovery-target-timeline="{{CLONE_TARGET_TIMELINE}}"
recovery_conf:
restore_command: envdir "{{CLONE_WALE_ENV_DIR}}" timeout "{{WAL_RESTORE_TIMEOUT}}"
/scripts/restore_command.sh "%f" "%p"
Expand Down