updated kopia state
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2023-12-12 16:12:12 +01:00
parent 0033bec333
commit e593741856
2 changed files with 17 additions and 8 deletions

View File

@ -5,23 +5,32 @@
import argparse import argparse
import subprocess import subprocess
from subprocess import Popen
KOPIA_BUCKET="kopia" KOPIA_BUCKET="kopia"
KOPIA_PASSWORD="{{ params.password|default('') }}" KOPIA_PASSWORD="{{ params.password|default('') }}"
KOPIA_CONFIG_PATH="/etc/kopia/{{ name }}/{{ name }}.config" KOPIA_CONFIG_PATH="/etc/kopia/{{ name }}/{{ name }}.config"
KOPIA_KEEP_LAST=7 KOPIA_KEEP_LAST=7
ENV = {
"KOPIA_PASSWORD": KOPIA_PASSWORD,
"KOPIA_CONFIG_PATH": KOPIA_CONFIG_PATH,
}
parser = argparse.ArgumentParser(prog='{{ name }} backup') parser = argparse.ArgumentParser(prog='{{ name }} backup')
def init(mode="filesystem", path=None, prefix=None, gateway=None, region=None, ak=None, sak=None): def init(mode="filesystem", path=None, prefix=None, gateway=None, region=None, ak=None, sak=None):
if mode == "filesystem" and path: if mode == "filesystem" and path:
repo_connect = subprocess.Popen(f"kopia repository connect filesystem --config-file={KOPIA_CONFIG_PATH} --path={path} -p {KOPIA_PASSWORD}", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) repo_connect = Popen(f"kopia repository connect filesystem --config-file={KOPIA_CONFIG_PATH} --path={path} -p {KOPIA_PASSWORD}", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
repo_create = subprocess.Popen(f"kopia repository create filesystem --config-file={KOPIA_CONFIG_PATH} --path={path} -p {KOPIA_PASSWORD}" , shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) repo_create = Popen(f"kopia repository create filesystem --config-file={KOPIA_CONFIG_PATH} --path={path} -p {KOPIA_PASSWORD}" , shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
elif mode == "s3" and prefix and gateway and region and ak and sak: 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={KOPIA_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 repository create s3 --config-file={KOPIA_CONFIG_PATH} --bucket={KOPIA_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={KOPIA_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={KOPIA_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 = subprocess.Popen(cmd_create, shell=True) run_create = Popen(cmd_create, shell=True)
run_create.wait() run_create.wait()
run_connect = subprocess.Popen(cmd_connect, shell=True) run_connect = Popen(cmd_connect, shell=True)
run_connect.wait() run_connect.wait()
else: else:
print("no valid mode or missing informations") print("no valid mode or missing informations")
@ -31,14 +40,14 @@ def init(mode="filesystem", path=None, prefix=None, gateway=None, region=None, a
def set_policy(compression="zstd"): def set_policy(compression="zstd"):
cmd_policy = f"kopia policy set --global --config-file={KOPIA_CONFIG_PATH} --compression={compression} --keep-latest={KOPIA_KEEP_LAST} --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 policy set --global --config-file={KOPIA_CONFIG_PATH} --compression={compression} --keep-latest={KOPIA_KEEP_LAST} --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 = subprocess.Popen(cmd_policy, shell=True) run_policy = Popen(cmd_policy, shell=True)
run_policy.wait() run_policy.wait()
return return
def run(): def run():
cmd_launch = f"kopia snapshot create {% for dir in params.dirs %}{{ dir.path }} {% endfor %} --config-file={KOPIA_CONFIG_PATH}" cmd_launch = f"kopia snapshot create {% for dir in params.dirs %}{{ dir.path }} {% endfor %} --config-file={KOPIA_CONFIG_PATH}"
run_launch = subprocess.Popen(cmd_launch, shell=True) run_launch = Popen(cmd_launch, shell=True)
run_launch.wait() run_launch.wait()
return return

View File

@ -1,4 +1,4 @@
{%- from "kopia/map.jinja" import kopia with context -%} {%- from "kopia/map.jinja" import kopia with context -%}
{% for ign in ignore -%} {%- for ign in ignore -%}
{{ ign }} {{ ign }}
{%- endfor %} {% endfor -%}