ansible-edda/scripts/restic/restic.py

44 lines
1.4 KiB
Python

import argparse
import keyring
import os
import subprocess
def keyring_get_password(service_name, username):
value = ""
while value == "":
value = keyring.get_password(service_name, username)
return value
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Helper script for working with restic backups")
parser.add_argument("--service", type=str, required=True,
help="Service with whose backup to work with")
parser.add_argument("--volume", type=str, required=True,
help="Volume with whose backup to work with")
parser.add_argument('rest', nargs=argparse.REMAINDER)
args = parser.parse_args()
scw_project_id = keyring_get_password("scaleway", "access_key")
scw_secret_key = keyring_get_password("scaleway", "secret_key")
restic_password = keyring_get_password("restic", "password")
scw_environ = {
"AWS_ACCESS_KEY_ID": scw_project_id,
"AWS_SECRET_ACCESS_KEY": scw_secret_key,
"RESTIC_PASSWORD": restic_password,
}
environ = {**os.environ, **scw_environ}
bucket_name = f"the-nine-worlds---{args.service}---{args.volume}"
cmd = ["restic",
"--option", "s3.storage-class=ONEZONE_IA",
"--repo", f"s3:https://s3.fr-par.scw.cloud/{bucket_name}"]
cmd += args.rest
output = subprocess.run(cmd, env=environ, check=False)
exit(output.returncode)