All checks were successful
buildbot/nix-build .#checks.aarch64-darwin.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.check-for-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-ts-api Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.package-default Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-deb Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-fakeroot Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-git Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-docs Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-iso-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-archlinux Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-e2fsprogs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-rpm Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-qemu" Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-nix Build done.
buildbot/nix-build .#checks.x86_64-linux.renderClanOptions Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-openssh Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-mypy" Build done.
buildbot/nix-build .#checks.x86_64-linux.deltachat Build done.
buildbot/nix-build .#checks.x86_64-linux.borgbackup Build done.
buildbot/nix-build .#checks.x86_64-linux.matrix-synapse Build done.
buildbot/nix-build .#checks.x86_64-linux.package-editor Build done.
buildbot/nix-build .#checks.x86_64-linux.package-merge-after-ci Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.postgresql Build done.
buildbot/nix-build .#checks.x86_64-linux.package-function-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.secrets Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-rsync Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sops Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-bash Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sshpass Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-zbar Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-apk Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-age Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-tor Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-no-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-default Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.container Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-example-valid Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-pytest Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-nix-unit-tests Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.package-deploy-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-impure-checks Build done.
buildbot/nix-build .#checks.x86_64-linux.treefmt Build done.
buildbot/nix-build .#checks.x86_64-linux.package-moonlight-sunshine-accept Build done.
buildbot/nix-build .#checks.x86_64-linux.package-pending-reviews Build done.
buildbot/nix-build .#checks.x86_64-linux.package-tea-create-pr Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotier-members Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotierone Build done.
buildbot/nix-build .#checks.x86_64-linux.package-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-without-core Build done.
buildbot/nix-build .#checks.x86_64-linux.package-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.template-minimal Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.wayland-proxy-virtwl Build done.
buildbot/nix-build .#checks.x86_64-linux.zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.syncthing Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-with-core Build done.
checks / checks-impure (pull_request) Successful in 2m10s
buildbot/nix-build .#checks.x86_64-linux.package-gui-install-test-ubuntu-22-04 Build done.
buildbot/nix-build .#checks.x86_64-linux.test-backups Build done.
buildbot/nix-build .#checks.x86_64-linux.flash Build done.
buildbot/nix-build .#checks.x86_64-linux.test-installation Build done.
buildbot/nix-eval Build done.
110 lines
3.6 KiB
Python
110 lines
3.6 KiB
Python
import argparse
|
|
import json
|
|
import subprocess
|
|
|
|
from ..completions import (
|
|
add_dynamic_completer,
|
|
complete_backup_providers_for_machine,
|
|
complete_machines,
|
|
)
|
|
from ..errors import ClanError
|
|
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.clan.core.backups"))
|
|
backup_folders = json.loads(machine.eval_nix("config.clan.core.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
|
|
# 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(
|
|
[pre_restore],
|
|
stdout=subprocess.PIPE,
|
|
extra_env=env,
|
|
)
|
|
if proc.returncode != 0:
|
|
raise ClanError(
|
|
f"failed to run preRestoreCommand: {pre_restore}, error was: {proc.stdout}"
|
|
)
|
|
|
|
proc = machine.target_host.run(
|
|
[backup_metadata["providers"][provider]["restore"]],
|
|
stdout=subprocess.PIPE,
|
|
extra_env=env,
|
|
)
|
|
if proc.returncode != 0:
|
|
raise ClanError(
|
|
f"failed to restore backup: {backup_metadata['providers'][provider]['restore']}"
|
|
)
|
|
|
|
if post_restore := backup_folders[service]["postRestoreCommand"]:
|
|
proc = machine.target_host.run(
|
|
[post_restore],
|
|
stdout=subprocess.PIPE,
|
|
extra_env=env,
|
|
)
|
|
if proc.returncode != 0:
|
|
raise ClanError(
|
|
f"failed to run postRestoreCommand: {post_restore}, error was: {proc.stdout}"
|
|
)
|
|
|
|
|
|
def restore_backup(
|
|
machine: Machine,
|
|
provider: str,
|
|
name: str,
|
|
service: str | None = None,
|
|
) -> None:
|
|
errors = []
|
|
if service is None:
|
|
backup_folders = json.loads(machine.eval_nix("config.clan.core.state"))
|
|
for _service in backup_folders:
|
|
try:
|
|
restore_service(machine, name, provider, _service)
|
|
except ClanError as e:
|
|
errors.append(f"{_service}: {e}")
|
|
else:
|
|
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:
|
|
if args.flake is None:
|
|
raise ClanError("Could not find clan flake toplevel directory")
|
|
machine = Machine(name=args.machine, flake=args.flake)
|
|
restore_backup(
|
|
machine=machine,
|
|
provider=args.provider,
|
|
name=args.name,
|
|
service=args.service,
|
|
)
|
|
|
|
|
|
def register_restore_parser(parser: argparse.ArgumentParser) -> None:
|
|
machine_action = parser.add_argument(
|
|
"machine", type=str, help="machine in the flake to create backups of"
|
|
)
|
|
add_dynamic_completer(machine_action, complete_machines)
|
|
provider_action = parser.add_argument(
|
|
"provider", type=str, help="backup provider to use"
|
|
)
|
|
add_dynamic_completer(provider_action, complete_backup_providers_for_machine)
|
|
parser.add_argument("name", type=str, help="Name of the backup to restore")
|
|
parser.add_argument("--service", type=str, help="name of the service to restore")
|
|
parser.set_defaults(func=restore_command)
|