1
0
forked from clan/clan-core

clan-cli backups: use new machine class for eval

This commit is contained in:
lassulus 2024-01-23 15:04:10 +01:00
parent 9cf670ee29
commit 3284224440
4 changed files with 11 additions and 18 deletions

View File

@ -27,11 +27,12 @@ in
];
};
};
test_backup_client = { pkgs, lib, ... }:
test_backup_client = { pkgs, lib, config, ... }:
let
dependencies = [
self
pkgs.stdenv.drvPath
clan.clanInternals.machines.x86_64-linux.test_backup_client.config.system.clan.deployment.file
] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
closureInfo = pkgs.closureInfo { rootPaths = dependencies; };
in

View File

@ -1,14 +1,16 @@
import argparse
import json
import logging
from ..errors import ClanError
from ..machines.machines import Machine
log = logging.getLogger(__name__)
def create_backup(machine: Machine, provider: str | None = None) -> None:
backup_scripts = json.loads(
machine.eval_nix(f"nixosConfigurations.{machine.name}.config.clanCore.backups")
)
log.info(f"creating backup for {machine.name}")
backup_scripts = json.loads(machine.eval_nix("config.clanCore.backups"))
if provider is None:
for provider in backup_scripts["providers"]:
proc = machine.host.run(

View File

@ -18,9 +18,7 @@ class Backup:
def list_provider(machine: Machine, provider: str) -> list[Backup]:
results = []
backup_metadata = json.loads(
machine.eval_nix(f"nixosConfigurations.{machine.name}.config.clanCore.backups")
)
backup_metadata = json.loads(machine.eval_nix("config.clanCore.backups"))
proc = machine.host.run(
["bash", "-c", backup_metadata["providers"][provider]["list"]],
stdout=subprocess.PIPE,

View File

@ -11,12 +11,8 @@ from .list import Backup, list_backups
def restore_service(
machine: Machine, backup: Backup, provider: str, service: str
) -> None:
backup_metadata = json.loads(
machine.eval_nix(f"nixosConfigurations.{machine.name}.config.clanCore.backups")
)
backup_folders = json.loads(
machine.eval_nix(f"nixosConfigurations.{machine.name}.config.clanCore.state")
)
backup_metadata = json.loads(machine.eval_nix("config.clanCore.backups"))
backup_folders = json.loads(machine.eval_nix("config.clanCore.state"))
folders = backup_folders[service]["folders"]
env = os.environ.copy()
env["ARCHIVE_ID"] = backup.archive_id
@ -77,11 +73,7 @@ def restore_backup(
if service is None:
for backup in backups:
if backup.archive_id == archive_id:
backup_folders = json.loads(
machine.eval_nix(
f"nixosConfigurations.{machine.name}.config.clanCore.state"
)
)
backup_folders = json.loads(machine.eval_nix("config.clanCore.state"))
for _service in backup_folders:
restore_service(machine, backup, provider, _service)
else: