restore: execute hooks, filter for volumes and container
This commit is contained in:
parent
cc59087b8c
commit
ac7c5fb50d
27
backupbot.py
27
backupbot.py
@ -110,31 +110,36 @@ def create(retries):
|
|||||||
@click.option('snapshot', '--snapshot', '-s', envvar='SNAPSHOT', default='latest')
|
@click.option('snapshot', '--snapshot', '-s', envvar='SNAPSHOT', default='latest')
|
||||||
@click.option('target', '--target', '-t', envvar='TARGET', default='/')
|
@click.option('target', '--target', '-t', envvar='TARGET', default='/')
|
||||||
@click.option('noninteractive', '--noninteractive', envvar='NONINTERACTIVE', is_flag=True)
|
@click.option('noninteractive', '--noninteractive', envvar='NONINTERACTIVE', is_flag=True)
|
||||||
def restore(snapshot, target, noninteractive):
|
@click.option('volumes', '--volumes', '-v', envvar='VOLUMES', multiple=True)
|
||||||
# Todo: recommend to shutdown the container
|
@click.option('container', '--container', '-c', envvar='CONTAINER', multiple=True)
|
||||||
service_paths = VOLUME_PATH
|
def restore(snapshot, target, noninteractive, volumes, container):
|
||||||
|
app_settings = parse_backup_labels('restore', container)
|
||||||
if SERVICE:
|
if SERVICE:
|
||||||
service_paths = service_paths + f'{SERVICE}_*'
|
app_settings = {SERVICE: app_settings[SERVICE]}
|
||||||
|
pre_commands, post_commands, backup_paths, apps = get_backup_details(app_settings, volumes)
|
||||||
snapshots = get_snapshots(snapshot_id=snapshot, app=SERVICE)
|
snapshots = get_snapshots(snapshot_id=snapshot, app=SERVICE)
|
||||||
if not snapshot:
|
if not snapshot:
|
||||||
logger.error("No Snapshots with ID {snapshots}")
|
logger.error("No Snapshots with ID {snapshots} for {apps} found.")
|
||||||
exit(1)
|
exit(1)
|
||||||
if not noninteractive:
|
if not noninteractive:
|
||||||
snapshot_date = datetime.fromisoformat(snapshots[0]['time'])
|
snapshot_date = datetime.fromisoformat(snapshots[0]['time'])
|
||||||
delta = datetime.now(tz=timezone.utc) - snapshot_date
|
delta = datetime.now(tz=timezone.utc) - snapshot_date
|
||||||
print(
|
print(f"You are going to restore Snapshot {snapshot} of {apps} at {target}")
|
||||||
f"You are going to restore Snapshot {snapshot} of {service_paths} at {target}")
|
print("The following volume paths will be restored:")
|
||||||
|
for p in backup_paths:
|
||||||
|
print(f'\t{p}')
|
||||||
print(f"This snapshot is {delta} old")
|
print(f"This snapshot is {delta} old")
|
||||||
print(
|
print(
|
||||||
f"THIS COMMAND WILL IRREVERSIBLY OVERWRITES {target}{service_paths.removeprefix('/')}")
|
f"THIS COMMAND WILL IRREVERSIBLY OVERWRITES FILES AT {target}")
|
||||||
prompt = input("Type YES (uppercase) to continue: ")
|
prompt = input("Type YES (uppercase) to continue: ")
|
||||||
if prompt != 'YES':
|
if prompt != 'YES':
|
||||||
logger.error("Restore aborted")
|
logger.error("Restore aborted")
|
||||||
exit(1)
|
exit(1)
|
||||||
print(f"Restoring Snapshot {snapshot} of {service_paths} at {target}")
|
print(f"Restoring Snapshot {snapshot} at {target}")
|
||||||
# TODO: use tags if no snapshot is selected, to use a snapshot including SERVICE
|
# TODO: use tags if no snapshot is selected, to use a snapshot including SERVICE
|
||||||
result = restic.restore(snapshot_id=snapshot,
|
run_commands(pre_commands)
|
||||||
include=service_paths, target_dir=target)
|
result = restic_restore(snapshot_id=snapshot, include=backup_paths, target_dir=target)
|
||||||
|
run_commands(post_commands)
|
||||||
logger.debug(result)
|
logger.debug(result)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user