-
Notifications
You must be signed in to change notification settings - Fork 1
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
Choose WAL-G backup by start time when cloning and deleting #1
Changes from 6 commits
a4f11b0
30b4d13
8416ba1
65a49d7
c8fcca2
899bc94
272fbf1
c788be7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import argparse | ||
import csv | ||
import json | ||
import logging | ||
import os | ||
import re | ||
|
@@ -40,14 +41,16 @@ def read_configuration(): | |
return options(args.scope, args.datadir, recovery_target_time, args.dry_run) | ||
|
||
|
||
def build_wale_command(command, datadir=None, backup=None): | ||
def build_wale_command(command, datadir=None, backup=None, extra_args=None): | ||
cmd = ['wal-g' if os.getenv('USE_WALG_RESTORE') == 'true' else 'wal-e'] + [command] | ||
if command == 'backup-fetch': | ||
if datadir is None or backup is None: | ||
raise Exception("backup-fetch requires datadir and backup arguments") | ||
cmd.extend([datadir, backup]) | ||
elif command != 'backup-list': | ||
raise Exception("invalid {0} command {1}".format(cmd[0], command)) | ||
if extra_args: | ||
cmd.extend(extra_args) | ||
return cmd | ||
|
||
|
||
|
@@ -57,8 +60,7 @@ def fix_output(output): | |
started = None | ||
for line in output.decode('utf-8').splitlines(): | ||
if not started: | ||
started = re.match(r'^name\s+last_modified\s+', line) | ||
started = re.match(r'^name\s+last_modified\s+', line) or re.match(r'^name\s+modified\s+', line) | ||
started = re.match(r'^(backup_)?name\s+(last_)?modified\s+', line) | ||
if started: | ||
line = line.replace(' modified ', ' last_modified ') | ||
if started: | ||
|
@@ -70,20 +72,25 @@ def choose_backup(backup_list, recovery_target_time): | |
|
||
match_timestamp = match = None | ||
for backup in backup_list: | ||
last_modified = parse(backup['last_modified']) | ||
last_modified = parse(backup['start_time' if os.getenv('USE_WALG_RESTORE') == 'true' else 'last_modified']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Simon, should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for bringing this up! The rational behind picking Either way, after having read the documentation you linked to I think you are absolutely correct. It does not make sense to pick a base backup that has not yet finished before the "recovery target". |
||
if last_modified < recovery_target_time: | ||
if match is None or last_modified > match_timestamp: | ||
match = backup | ||
match_timestamp = last_modified | ||
if match is not None: | ||
return match['name'] | ||
return match.get('name', match['backup_name']) | ||
|
||
|
||
def list_backups(env): | ||
backup_list_cmd = build_wale_command('backup-list') | ||
output = subprocess.check_output(backup_list_cmd, env=env) | ||
reader = csv.DictReader(fix_output(output), dialect='excel-tab') | ||
return list(reader) | ||
if os.getenv('USE_WALG_RESTORE') == 'true': | ||
backup_list_cmd = build_wale_command('backup-list', extra_args=['--detail', '--json']) | ||
output = subprocess.check_output(backup_list_cmd, env=env) | ||
return json.loads(output or 'null') | ||
else: | ||
backup_list_cmd = build_wale_command('backup-list') | ||
output = subprocess.check_output(backup_list_cmd, env=env) | ||
reader = csv.DictReader(fix_output(output), dialect='excel-tab') | ||
return list(reader) | ||
|
||
|
||
def get_clone_envdir(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure this matches up with the fix upstream so that we don't reintroduce the bug: zalando#1026