Merge pull request 'Expand backup and restore capabilities w.r.t. postgresql.' (#1582) from synapse into main
This commit is contained in:
@@ -343,7 +343,7 @@ def main() -> None:
|
||||
if len(sys.argv) == 1:
|
||||
parser.print_help()
|
||||
|
||||
if args.debug:
|
||||
if getattr(args, "debug", False):
|
||||
setup_logging(logging.DEBUG, root_log_name=__name__.split(".")[0])
|
||||
log.debug("Debug log activated")
|
||||
if flatpak.is_flatpak():
|
||||
|
||||
@@ -14,10 +14,16 @@ from ..machines.machines import Machine
|
||||
def restore_service(machine: Machine, name: str, provider: str, service: str) -> None:
|
||||
backup_metadata = json.loads(machine.eval_nix("config.clanCore.backups"))
|
||||
backup_folders = json.loads(machine.eval_nix("config.clanCore.state"))
|
||||
|
||||
if service not in backup_folders:
|
||||
msg = f"Service {service} not found in configuration. Available services are: {', '.join(backup_folders.keys())}"
|
||||
raise ClanError(msg)
|
||||
|
||||
folders = backup_folders[service]["folders"]
|
||||
env = {}
|
||||
env["NAME"] = name
|
||||
env["FOLDERS"] = ":".join(folders)
|
||||
# FIXME: If we have too many folder this might overflow the stack.
|
||||
env["FOLDERS"] = ":".join(set(folders))
|
||||
|
||||
if pre_restore := backup_folders[service]["preRestoreCommand"]:
|
||||
proc = machine.target_host.run(
|
||||
@@ -58,12 +64,23 @@ def restore_backup(
|
||||
name: str,
|
||||
service: str | None = None,
|
||||
) -> None:
|
||||
errors = []
|
||||
if service is None:
|
||||
backup_folders = json.loads(machine.eval_nix("config.clanCore.state"))
|
||||
for _service in backup_folders:
|
||||
restore_service(machine, name, provider, _service)
|
||||
try:
|
||||
restore_service(machine, name, provider, _service)
|
||||
except ClanError as e:
|
||||
errors.append(f"{_service}: {e}")
|
||||
else:
|
||||
restore_service(machine, name, provider, service)
|
||||
try:
|
||||
restore_service(machine, name, provider, service)
|
||||
except ClanError as e:
|
||||
errors.append(f"{service}: {e}")
|
||||
if errors:
|
||||
raise ClanError(
|
||||
"Restore failed for the following services:\n" + "\n".join(errors)
|
||||
)
|
||||
|
||||
|
||||
def restore_command(args: argparse.Namespace) -> None:
|
||||
|
||||
Reference in New Issue
Block a user