Skip to content

Commit 18b7f08

Browse files
committed
add support for kopia maintenance
1 parent 3c4b29e commit 18b7f08

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

hasadna_k8s/ceph/cli.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22
import json
3+
import traceback
4+
35
import click
46

57

@@ -17,6 +19,26 @@ def pvc_backup(namespace, pvc_name):
1719

1820

1921
@main.command()
20-
def pvc_backup_all():
22+
@click.option('--full', is_flag=True)
23+
def maintenance(**kwargs):
24+
from .kopia import maintenance
25+
maintenance(**kwargs)
26+
27+
28+
@main.command()
29+
@click.option('--with-full-maintenance', is_flag=True)
30+
def pvc_backup_all(with_full_maintenance):
2131
from .pvc_backup import main_all
22-
main_all()
32+
pvc_backup_failed = False
33+
try:
34+
main_all()
35+
except Exception as e:
36+
if with_full_maintenance:
37+
traceback.print_exc()
38+
pvc_backup_failed = True
39+
else:
40+
raise
41+
if with_full_maintenance:
42+
from .kopia import maintenance
43+
maintenance(full=True)
44+
assert not pvc_backup_failed

hasadna_k8s/ceph/kopia.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import socket
2+
import getpass
3+
import subprocess
4+
5+
6+
def maintenance(full=False):
7+
kopia_user = f'{getpass.getuser()}@{socket.gethostname()}'
8+
subprocess.check_call([
9+
'kopia', 'maintenance', 'set', f'--owner={kopia_user}',
10+
])
11+
cmd = [
12+
'kopia', 'maintenance', 'run'
13+
]
14+
if full:
15+
cmd.append('--full')
16+
subprocess.check_call(cmd)

0 commit comments

Comments
 (0)