-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
106 lines (88 loc) · 4.33 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import streamlit as st
# Title of the app
st.title("ZFS Command Generator")
# Sidebar for navigation
st.sidebar.title("ZFS Command Options")
action = st.sidebar.radio("Select Action", ["Incremental Command", "Full Command"])
# Helper function to copy command to clipboard
def copy_to_clipboard(command):
try:
import pyperclip
pyperclip.copy(command)
st.success("Command copied to clipboard!")
except Exception as e:
st.error(f"Failed to copy: {e}")
if action == "Incremental Command":
st.header("Generate Incremental ZFS Command")
# Form inputs for incremental command
first_snapshot = st.text_input("First Incremental Snapshot")
last_snapshot = st.text_input("Last Incremental Snapshot")
destination_san = st.text_input("Destination SAN for Incrementals")
force_sync = st.checkbox("Force Sync (-F): (Will Mirror Source)")
compression = st.checkbox("Enable Compression (-c)", value=True)
use_mbuffer = st.checkbox("Use mbuffer", value=True)
estimate_size = st.checkbox("Estimate Transfer Size")
if st.button("Generate and Copy Incremental Command"):
if first_snapshot and last_snapshot and destination_san:
first_snapshot_prefix = first_snapshot.split('/')[0]
compression_flag = "-c" if compression else ""
flag = "-sF" if force_sync else "-s"
destination_pool = f"{destination_san}p1"
if destination_san.startswith(first_snapshot_prefix[:2]):
destination_san += "-san"
dataset_name = first_snapshot.split('@')[0].split('/', 1)[1]
# Generate the main incremental command
if use_mbuffer:
incremental_command = (
f'zfs send {compression_flag} -RI {first_snapshot} {last_snapshot} | '
f'mbuffer -s 4M -m 8G | ssh {destination_san} '
f'"mbuffer -s 4M -m 8G | zfs receive {flag} {destination_pool}/{dataset_name}"'
)
else:
incremental_command = (
f'zfs send {compression_flag} -RI {first_snapshot} {last_snapshot} | '
f'ssh {destination_san} "zfs receive {flag} {destination_pool}/{dataset_name}"'
)
# Generate the size estimation command
size_estimation_command = ""
if estimate_size:
size_estimation_command = (
f'zfs send -c -n -v -RI {first_snapshot} {last_snapshot}'
)
st.subheader("Estimated Transfer Size Command")
st.code(size_estimation_command, language="bash")
st.subheader("Incremental Command")
st.code(incremental_command, language="bash")
copy_to_clipboard(incremental_command)
else:
st.warning("Please fill in all fields.")
elif action == "Full Command":
st.header("Generate Full ZFS Command")
# Form inputs for full command
full_snapshot = st.text_input("Full Snapshot")
destination_full_san = st.text_input("Destination SAN for Full Snapshot")
use_mbuffer = st.checkbox("Use mbuffer", value=True)
if st.button("Generate and Copy Full Command"):
if full_snapshot and destination_full_san:
destination_full_pool = f"{destination_full_san}p1"
full_snapshot_prefix = full_snapshot.split('/')[0]
if destination_full_san.startswith(full_snapshot_prefix[:2]):
destination_full_san += "-san"
dataset_name = full_snapshot.split('@')[0].split('/', 1)[1]
# Generate the full command
if use_mbuffer:
full_command = (
f'zfs send -c {full_snapshot} | '
f'mbuffer -s 4M -m 4G | ssh {destination_full_san} '
f'"mbuffer -s 4M -m 4G | zfs receive -F {destination_full_pool}/{dataset_name}"'
)
else:
full_command = (
f'zfs send -c {full_snapshot} | '
f'ssh {destination_full_san} "zfs receive -F {destination_full_pool}/{dataset_name}"'
)
st.subheader("Full Command")
st.code(full_command, language="bash")
copy_to_clipboard(full_command)
else:
st.warning("Please fill in all fields.")