summaryrefslogtreecommitdiff
path: root/subplot/obnam.py
diff options
context:
space:
mode:
Diffstat (limited to 'subplot/obnam.py')
-rw-r--r--subplot/obnam.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/subplot/obnam.py b/subplot/obnam.py
index 79a4649..ee48985 100644
--- a/subplot/obnam.py
+++ b/subplot/obnam.py
@@ -6,6 +6,7 @@ import re
import requests
import shutil
import socket
+import subprocess
import tarfile
import time
import urllib3
@@ -34,6 +35,8 @@ def start_chunk_server(ctx):
logging.debug(f"Picked randomly port for obnam-server: {config['port']}")
ctx["config"] = config
+ ctx["server_name"] = "localhost"
+ ctx["server_port"] = port
ctx["url"] = f"http://localhost:{port}"
start_daemon(ctx, "obnam-server", [_binary("obnam-server"), filename])
@@ -213,3 +216,61 @@ def _expand_vars(ctx, s):
result.append(value)
s = s[m.end() :]
return "".join(result)
+
+
+def install_obnam(ctx):
+ runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"]
+ srcdir = globals()["srcdir"]
+
+ # Add the directory with built Rust binaries to the path.
+ runcmd_prepend_to_path(ctx, dirname=os.path.join(srcdir, "target", "debug"))
+
+
+def configure_client(ctx, filename=None):
+ get_file = globals()["get_file"]
+
+ config = get_file(filename)
+ ctx["client-config"] = yaml.safe_load(config)
+
+
+def run_obnam_backup(ctx, filename=None):
+ runcmd_run = globals()["runcmd_run"]
+
+ _write_obnam_client_config(ctx, filename)
+ runcmd_run(ctx, ["env", "RUST_LOG=obnam", "obnam-backup", filename])
+
+
+def _write_obnam_client_config(ctx, filename):
+ config = ctx["client-config"]
+ config["server_name"] = ctx["server_name"]
+ config["server_port"] = ctx["server_port"]
+ with open(filename, "w") as f:
+ yaml.safe_dump(config, stream=f)
+
+
+def run_obnam_restore(ctx, filename=None, genid=None, dbname=None, todir=None):
+ runcmd_run = globals()["runcmd_run"]
+
+ genid = ctx["vars"][genid]
+ _write_obnam_client_config(ctx, filename)
+ runcmd_run(
+ ctx, ["env", "RUST_LOG=obnam", "obnam-restore", filename, genid, dbname, todir]
+ )
+
+
+def capture_generation_id(ctx, varname=None):
+ runcmd_get_stdout = globals()["runcmd_get_stdout"]
+
+ stdout = runcmd_get_stdout(ctx)
+ gen_id = "unknown"
+ for line in stdout.splitlines():
+ if line.startswith("gen id:"):
+ gen_id = line.split()[-1]
+
+ v = ctx.get("vars", {})
+ v[varname] = gen_id
+ ctx["vars"] = v
+
+
+def live_and_restored_data_match(ctx, live=None, restore=None):
+ subprocess.check_call(["diff", "-rq", f"{live}/.", f"{restore}/{live}/."])