Add restic helper script

This commit is contained in:
Wojciech Kozlowski 2023-07-15 22:49:33 +02:00
parent 7ce81fb818
commit 6fb5d83d4c

36
scripts/restic/restic.py Normal file
View File

@ -0,0 +1,36 @@
import argparse
import keyring
import os
import subprocess
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)