diff --git a/main.py b/main.py new file mode 100644 index 0000000..2f2c7ec --- /dev/null +++ b/main.py @@ -0,0 +1,56 @@ +import json +import socket +import subprocess + +REMOTES = {"bee1", "bee2", "bee3"} +CUR_PROJECT = "default" +BAK_PROJECT = "backs" + + +def run_and_load(cmd_list): + std = subprocess.run( + cmd_list, + capture_output=True, + ).stdout.decode() + return json.loads(std) + + +if __name__ == "__main__": + curr_host = socket.gethostname() + other_nodes = REMOTES.difference([curr_host]) + containers = run_and_load( + [ + "lxc", + "list", + "-f", + "json", + "--project", + CUR_PROJECT, + ] + ) + cont_names = [x["name"] for x in containers] + for name in cont_names: + print(f"Snapshot {name}") + std = subprocess.run( + [ + "lxc", + "snapshot", + name, + "--project", + CUR_PROJECT, + ], + ) + for node in other_nodes: + print(f"export {name} on {node}") + std = subprocess.run( + [ + "lxc", + "cp", + name, + f"{node}:{name}", + "--target-project", + BAK_PROJECT, + "--stateless", + "--refresh", + ], + )