From 6e1e33b3e33709728f9c1051e8d58c395dff2e82 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sat, 9 Mar 2024 18:48:05 +0100 Subject: [PATCH] updated kopia state --- states/kopia/templates/kopia_backup.py.j2 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/states/kopia/templates/kopia_backup.py.j2 b/states/kopia/templates/kopia_backup.py.j2 index 94d8ba8..bf2dd22 100644 --- a/states/kopia/templates/kopia_backup.py.j2 +++ b/states/kopia/templates/kopia_backup.py.j2 @@ -8,7 +8,7 @@ import subprocess from subprocess import Popen, PIPE - +KOPIA_EXEC="/usr/local/bin/kopia" KOPIA_PASSWORD="{{ params.password|default('') }}" KOPIA_CONFIG_PATH="/etc/kopia/{{ name }}/repo.config" @@ -22,11 +22,11 @@ parser = argparse.ArgumentParser(prog='{{ name }} backup') def init(mode="filesystem", path=None, bucket=None, prefix=None, gateway=None, region=None, ak=None, sak=None): if mode == "filesystem" and path: - repo_connect = Popen(f"kopia repository connect filesystem --config-file={KOPIA_CONFIG_PATH} --path={path} -p {KOPIA_PASSWORD}", shell=True, stdout=PIPE, stderr=PIPE) - repo_create = Popen(f"kopia repository create filesystem --config-file={KOPIA_CONFIG_PATH} --path={path} -p {KOPIA_PASSWORD}" , shell=True, stdout=PIPE, stderr=PIPE) + repo_connect = Popen(f"{KOPIA_EXEC} repository connect filesystem --config-file={KOPIA_CONFIG_PATH} --path={path} -p {KOPIA_PASSWORD}", shell=True, stdout=PIPE, stderr=PIPE) + repo_create = Popen(f"{KOPIA_EXEC} repository create filesystem --config-file={KOPIA_CONFIG_PATH} --path={path} -p {KOPIA_PASSWORD}" , shell=True, stdout=PIPE, stderr=PIPE) elif mode == "s3" and prefix and gateway and region and ak and sak: - cmd_create = f"kopia repository create s3 --config-file={KOPIA_CONFIG_PATH} --bucket={bucket} --prefix={prefix}/ --endpoint={gateway} --region={region} --access-key={ak} --secret-access-key={sak} -p {KOPIA_PASSWORD} --no-check-for-updates --description='{{ name }} repository'" - cmd_connect = f"kopia repository connect s3 --config-file={KOPIA_CONFIG_PATH} --bucket={bucket} --prefix={prefix}/ --endpoint={gateway} --region={region} --access-key={ak} --secret-access-key={sak} -p {KOPIA_PASSWORD} --no-check-for-updates --description='{{ name }} repository'" + cmd_create = f"{KOPIA_EXEC} repository create s3 --config-file={KOPIA_CONFIG_PATH} --bucket={bucket} --prefix={prefix}/ --endpoint={gateway} --region={region} --access-key={ak} --secret-access-key={sak} -p {KOPIA_PASSWORD} --no-check-for-updates --description='{{ name }} repository'" + cmd_connect = f"{KOPIA_EXEC} repository connect s3 --config-file={KOPIA_CONFIG_PATH} --bucket={bucket} --prefix={prefix}/ --endpoint={gateway} --region={region} --access-key={ak} --secret-access-key={sak} -p {KOPIA_PASSWORD} --no-check-for-updates --description='{{ name }} repository'" run_create = Popen(cmd_create, shell=True, stdout=PIPE, stderr=PIPE) run_create.wait() if run_create.returncode == 0: @@ -42,7 +42,7 @@ def init(mode="filesystem", path=None, bucket=None, prefix=None, gateway=None, r def set_policy(compression="zstd"): - cmd_policy = f"kopia policy set --global --config-file={KOPIA_CONFIG_PATH} --compression={compression} --keep-latest={{ params.keep_latest|default(7) }} --keep-hourly 0 --keep-daily {{ params.keep_daily|default(7) }} --keep-weekly {{ params.keep_weekly|default(4) }} --keep-monthly {{ params.keep_monthly|default(6) }} --keep-annual 0 --one-file-system=true" + cmd_policy = f"{KOPIA_EXEC} policy set --global --config-file={KOPIA_CONFIG_PATH} --compression={compression} --keep-latest={{ params.keep_latest|default(7) }} --keep-hourly 0 --keep-daily {{ params.keep_daily|default(7) }} --keep-weekly {{ params.keep_weekly|default(4) }} --keep-monthly {{ params.keep_monthly|default(6) }} --keep-annual 0 --one-file-system=true" run_policy = Popen(cmd_policy, shell=True, stdout=PIPE, stderr=PIPE) run_policy.wait() if run_policy.returncode == 0: @@ -52,8 +52,8 @@ def set_policy(compression="zstd"): def set_cache(): rcs = [] - cmds_cache = [f"kopia cache set --content-cache-size-mb 1000 --config-file={KOPIA_CONFIG_PATH}", - f"kopia cache set --content-cache-size-limit-mb 2000 --config-file={KOPIA_CONFIG_PATH}"] + cmds_cache = [f"{KOPIA_EXEC} cache set --content-cache-size-mb 1000 --config-file={KOPIA_CONFIG_PATH}", + f"{KOPIA_EXEC} cache set --content-cache-size-limit-mb 2000 --config-file={KOPIA_CONFIG_PATH}"] for cmd_cache in cmds_cache: run_cache = Popen(cmd_cache, shell=True, stdout=PIPE, stderr=PIPE) run_cache.wait() @@ -72,14 +72,14 @@ def run(before_tasks=[]): if not all(rcs): return False - cmd_launch = f"kopia snapshot create {{ params.dirs|map(attribute='path')|join(' ') }} --config-file={KOPIA_CONFIG_PATH}" + cmd_launch = f"{KOPIA_EXEC} snapshot create {{ params.dirs|map(attribute='path')|join(' ') }} --config-file={KOPIA_CONFIG_PATH}" run_launch = Popen(cmd_launch, shell=True) run_launch.wait() return run_launch.returncode == 0 def list_snapshots(): - cmd_list = f"kopia snapshot list --config-file={KOPIA_CONFIG_PATH}" + cmd_list = f"{KOPIA_EXEC} snapshot list --config-file={KOPIA_CONFIG_PATH}" run_list = Popen(cmd_list, shell=True) run_list.wait() return run_list.returncode == 0