fix(release): retain and upload the same monthly recovery set
This commit is contained in:
@@ -16,6 +16,12 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
BASH = 'C:/Program Files/Git/bin/bash.exe' if os.name == 'nt' else shutil.which('bash')
|
||||
|
||||
|
||||
def retention_and_upload_gate(source):
|
||||
start = source.index('if ! backup_recovery_volumes; then')
|
||||
after_recovery = source.index('\nfi\n', start) + 4
|
||||
return source[after_recovery:source.index('\nif [ "${DEPLOY_BACKUP_ONLY:-false}"', after_recovery)]
|
||||
|
||||
|
||||
class BackupConnectionTests(unittest.TestCase):
|
||||
def backup(self, connection):
|
||||
source = (ROOT / 'deploy/deploy.sh').read_text(encoding='utf-8')
|
||||
@@ -92,30 +98,35 @@ class BackupConnectionTests(unittest.TestCase):
|
||||
class BackupUploadTests(unittest.TestCase):
|
||||
def upload(self, fail_operation=''):
|
||||
source = (ROOT / 'deploy/deploy.sh').read_text(encoding='utf-8')
|
||||
start = source.index('upload_current_backup_set() {')
|
||||
function = source[start:source.index('\n}\n', start) + 3]
|
||||
gate_start = source.index('if ! apply_backup_retention || ! upload_current_backup_set; then')
|
||||
gate = source[gate_start:source.index('\nfi\n', gate_start) + 4]
|
||||
functions = []
|
||||
for name in ['apply_backup_retention', 'upload_current_backup_set']:
|
||||
start = source.index(name + '() {')
|
||||
functions.append(source[start:source.index('\n}\n', start) + 3])
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
folder = Path(temporary)
|
||||
for filename in ['jobtracker-db-synthetic.sql.gz', 'jobtracker-files-synthetic.tar.gz',
|
||||
'jobtracker-db-older.sql.gz']:
|
||||
(folder / filename).touch()
|
||||
(folder / 'monthly' / '2099-01').mkdir(parents=True)
|
||||
script = '\n'.join([
|
||||
'set -euo pipefail',
|
||||
'BACKUP_DIR=' + shlex.quote(folder.as_posix()),
|
||||
'BACKUP_STAMP=synthetic',
|
||||
'BACKUP_RCLONE_REMOTE=fixture:encrypted/',
|
||||
'FAIL_OPERATION=' + shlex.quote(fail_operation),
|
||||
'date() { echo 2099-01; }',
|
||||
'apply_backup_retention() { return 0; }',
|
||||
'date() {',
|
||||
' if [ "$FAIL_OPERATION" = clock ]; then return 2; fi;',
|
||||
' if [ "$FAIL_OPERATION" = rollover ] && [ -f "$BACKUP_DIR/tick" ]; then echo 2099-02;',
|
||||
' else touch "$BACKUP_DIR/tick"; echo 2099-01; fi;',
|
||||
'}',
|
||||
'find() { return 0; }',
|
||||
'rclone() {',
|
||||
' printf "UPLOAD %s %s %s\\n" "$1" "$3" "$4";',
|
||||
' if [ "$1" = "$FAIL_OPERATION" ]; then return 23; fi;',
|
||||
' if [ "$FAIL_OPERATION" = missing-monthly ] && [ -d "$BACKUP_DIR/monthly/2099-01" ]; then',
|
||||
' mv "$BACKUP_DIR/monthly/2099-01" "$BACKUP_DIR/unavailable-snapshot"; fi;',
|
||||
'}',
|
||||
function,
|
||||
gate,
|
||||
*functions,
|
||||
retention_and_upload_gate(source),
|
||||
'echo "DEPLOY WOULD CONTINUE"',
|
||||
])
|
||||
result = subprocess.run([BASH, '--noprofile', '--norc'], input=script,
|
||||
@@ -137,6 +148,25 @@ class BackupUploadTests(unittest.TestCase):
|
||||
self.assertIn('DEPLOY WOULD CONTINUE', result.stdout)
|
||||
self.assertIn('Current recovery set copied to configured off-host remote.', result.stdout)
|
||||
|
||||
def test_month_rollover_uploads_the_retained_snapshot(self):
|
||||
result, calls = self.upload('rollover')
|
||||
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
|
||||
self.assertIn('UPLOAD copy fixture:encrypted/monthly/2099-01 --immutable', calls)
|
||||
|
||||
def test_clock_failure_blocks_retention_and_upload(self):
|
||||
result, calls = self.upload('clock')
|
||||
self.assertNotEqual(0, result.returncode, result.stdout + result.stderr)
|
||||
self.assertEqual([], calls)
|
||||
self.assertNotIn('Monthly recovery set retained', result.stdout)
|
||||
self.assertNotIn('DEPLOY WOULD CONTINUE', result.stdout)
|
||||
|
||||
def test_missing_monthly_snapshot_stops_the_gate(self):
|
||||
result, calls = self.upload('missing-monthly')
|
||||
self.assertNotEqual(0, result.returncode, result.stdout + result.stderr)
|
||||
self.assertEqual(2, len(calls))
|
||||
self.assertNotIn('Current recovery set copied', result.stdout)
|
||||
self.assertNotIn('DEPLOY WOULD CONTINUE', result.stdout)
|
||||
|
||||
def test_daily_copy_failure_stops_before_remaining_files_and_monthly_copy(self):
|
||||
result, calls = self.upload('copyto')
|
||||
self.assertEqual(1, result.returncode, result.stdout + result.stderr)
|
||||
@@ -162,8 +192,7 @@ class BackupRetentionTests(unittest.TestCase):
|
||||
source = (ROOT / 'deploy/deploy.sh').read_text(encoding='utf-8')
|
||||
start = source.index('apply_backup_retention() {')
|
||||
function = source[start:source.index('\n}\n', start) + 3]
|
||||
gate_start = source.index('if ! apply_backup_retention || ! upload_current_backup_set; then')
|
||||
gate = source[gate_start:source.index('\nfi\n', gate_start) + 4]
|
||||
gate = retention_and_upload_gate(source)
|
||||
fixtures = {'jobtracker-db-synthetic.sql.gz': b'database fixture',
|
||||
'jobtracker-files-synthetic.tar.gz': b'files fixture'}
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
|
||||
Reference in New Issue
Block a user