add volumes
This commit is contained in:
62
main.py
62
main.py
@@ -5,6 +5,7 @@ import subprocess
|
|||||||
REMOTES = {"bee1", "bee2", "bee3"}
|
REMOTES = {"bee1", "bee2", "bee3"}
|
||||||
CUR_PROJECT = "default"
|
CUR_PROJECT = "default"
|
||||||
BAK_PROJECT = "backs"
|
BAK_PROJECT = "backs"
|
||||||
|
STORAGE = "default"
|
||||||
|
|
||||||
|
|
||||||
def run_and_load(cmd_list):
|
def run_and_load(cmd_list):
|
||||||
@@ -15,9 +16,56 @@ def run_and_load(cmd_list):
|
|||||||
return json.loads(std)
|
return json.loads(std)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def backup_custom_volumes(nodes):
|
||||||
curr_host = socket.gethostname()
|
vols = run_and_load(
|
||||||
other_nodes = REMOTES.difference([curr_host])
|
[
|
||||||
|
"lxc",
|
||||||
|
"storage",
|
||||||
|
"volume",
|
||||||
|
"list",
|
||||||
|
STORAGE,
|
||||||
|
"-f",
|
||||||
|
"json",
|
||||||
|
"--project",
|
||||||
|
CUR_PROJECT,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
vols_names = [
|
||||||
|
x["name"] for x in vols if x["type"] == "custom" and not "/" in x["name"]
|
||||||
|
]
|
||||||
|
|
||||||
|
for name in vols_names:
|
||||||
|
print(f"Snapshot volume {name}")
|
||||||
|
std = subprocess.run(
|
||||||
|
[
|
||||||
|
"lxc",
|
||||||
|
"storage",
|
||||||
|
"volume",
|
||||||
|
"snapshot",
|
||||||
|
STORAGE,
|
||||||
|
name,
|
||||||
|
"--project",
|
||||||
|
CUR_PROJECT,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
for node in nodes:
|
||||||
|
print(f"export volume {name} on {node}")
|
||||||
|
std = subprocess.run(
|
||||||
|
[
|
||||||
|
"lxc",
|
||||||
|
"storage",
|
||||||
|
"volume",
|
||||||
|
"cp",
|
||||||
|
f"{STORAGE}/{name}",
|
||||||
|
f"{node}:{STORAGE}/{name}",
|
||||||
|
"--target-project",
|
||||||
|
BAK_PROJECT,
|
||||||
|
"--refresh",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def backup_containers(nodes):
|
||||||
containers = run_and_load(
|
containers = run_and_load(
|
||||||
[
|
[
|
||||||
"lxc",
|
"lxc",
|
||||||
@@ -40,7 +88,7 @@ if __name__ == "__main__":
|
|||||||
CUR_PROJECT,
|
CUR_PROJECT,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
for node in other_nodes:
|
for node in nodes:
|
||||||
print(f"export {name} on {node}")
|
print(f"export {name} on {node}")
|
||||||
std = subprocess.run(
|
std = subprocess.run(
|
||||||
[
|
[
|
||||||
@@ -54,3 +102,9 @@ if __name__ == "__main__":
|
|||||||
"--refresh",
|
"--refresh",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
curr_host = socket.gethostname()
|
||||||
|
other_nodes = REMOTES.difference([curr_host])
|
||||||
|
backup_containers(other_nodes)
|
||||||
|
|||||||
Reference in New Issue
Block a user