57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
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",
|
|
],
|
|
)
|