forked from clan/clan-core
backups: skip preRestore and postRestore if not specified by a service
This commit is contained in:
parent
aa659bcc17
commit
539df08706
@ -17,18 +17,18 @@
|
||||
Folder where state resides in
|
||||
'';
|
||||
};
|
||||
preRestoreScript = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = ":";
|
||||
preRestoreCommand = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
script to run before restoring the state dir from a backup
|
||||
|
||||
Utilize this to stop services which currently access these folders
|
||||
'';
|
||||
};
|
||||
postRestoreScript = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = ":";
|
||||
postRestoreCommand = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
script to restore the service after the state dir was restored from a backup
|
||||
|
||||
|
@ -14,14 +14,15 @@ def restore_service(machine: Machine, name: str, provider: str, service: str) ->
|
||||
env["NAME"] = name
|
||||
env["FOLDERS"] = ":".join(folders)
|
||||
|
||||
if pre_restore := backup_folders[service]["preRestoreCommand"]:
|
||||
proc = machine.target_host.run(
|
||||
[backup_folders[service]["preRestoreScript"]],
|
||||
[pre_restore],
|
||||
stdout=subprocess.PIPE,
|
||||
extra_env=env,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
raise ClanError(
|
||||
f"failed to run preRestoreScript: {backup_folders[service]['preRestoreScript']}, error was: {proc.stdout}"
|
||||
f"failed to run preRestoreCommand: {pre_restore}, error was: {proc.stdout}"
|
||||
)
|
||||
|
||||
proc = machine.target_host.run(
|
||||
@ -34,14 +35,15 @@ def restore_service(machine: Machine, name: str, provider: str, service: str) ->
|
||||
f"failed to restore backup: {backup_metadata['providers'][provider]['restore']}"
|
||||
)
|
||||
|
||||
if post_restore := backup_folders[service]["postRestoreCommand"]:
|
||||
proc = machine.target_host.run(
|
||||
[backup_folders[service]["postRestoreScript"]],
|
||||
[post_restore],
|
||||
stdout=subprocess.PIPE,
|
||||
extra_env=env,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
raise ClanError(
|
||||
f"failed to run postRestoreScript: {backup_folders[service]['postRestoreScript']}, error was: {proc.stdout}"
|
||||
f"failed to run postRestoreCommand: {post_restore}, error was: {proc.stdout}"
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user