-
Notifications
You must be signed in to change notification settings - Fork 57
/
zrep_top
263 lines (246 loc) · 5.49 KB
/
zrep_top
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash --noprofile
# For more detailed documentation, see zrep.txt or zrep.overview.txt
# note to self: always make this 3 fields
ZREP_VERSION=2.0.2
################################################
######## start of included files from zrep_top here
AWKinclude zrep_vars
AWKinclude zrep_status
AWKinclude zrep_snap
AWKinclude zrep_sync
AWKinclude zrep_failover
######## zrep_top continues here
usage(){
echo zrep v${ZREP_VERSION}: a program to replicate a zfs filesystem to another
echo in an ongoing basis.
echo
echo " Philip Brown, 2012-2022"
echo
echo Simple usage summary:
echo 'zrep (init|-i) [-f] [-v] ZFS/fs remotehost remoteZFSpool/fs'
echo 'zrep (sync|-S) [-f] [-v] [-q seconds] ZFS/fs'
echo 'zrep (sync|-S) [-f] [-v] [-q seconds] all'
echo 'zrep (sync|-S) [-f] [-v] ZFS/fs snapshot -- temporary retroactive sync'
echo 'zrep refresh [-f] [-v] ZFS/fs -- pull partner of sync'
echo 'zrep failover [-L] ZFS/fs [remotehost]'
echo 'zrep takeover [-L] ZFS/fs [remotehost]'
echo
echo "Status and side operations"
echo 'zrep (status|-s) [-v] [(-a|ZFS/fs)]'
echo 'zrep (status|-s) -m [ZFS/fs]'
echo 'zrep (list|-l) [-Lv] [fs/names]'
echo 'zrep (list|-l) -s [fs/names] -- list all relevant zrep snapshots'
echo 'zrep getlastsent ZFS/fs -- prints out snapshot of last successful sync sent'
echo 'zrep (expire|-e) [-L] (ZFS/fs ...)|(all)|()'
echo 'zrep uptodate ZFS/fs -- returns 0 if no writes since last sync.'
echo 'zrep version'
echo 'zrep clear [-f] ZFS/fs -- REMOVE ZREP CONFIG AND SNAPS FROM FILESYSTEM'
echo 'zrep (changeconfig|-C) [-f] ZFS/fs remotehost remoteZFSpool/fs'
echo 'zrep (changeconfig|-C) [-f] [-d] ZFS/fs srchost srcZFSpool/fs'
echo ''
echo ' -q option to sync says to Quietly ignore locked filesystems'
echo ' that have synced more recently than the given amount of seconds'
echo ''
echo 'Paired commands for high-transaction systems:'
echo ' zrep snaponly (ZFS/fs ... |all)'
echo ' zrep synconly (ZFS/fs ...|all)'
echo 'The above two commands split the simple sync subcommand, into two'
echo 'separate steps, so that a database, etc. may resume while the sync'
echo 'completes in the background'
echo ''
echo 'zrep defaults to using ssh. However, if remotehost is set to localhost,'
echo 'zrep will use a simple pipe instead.'
echo ''
echo ' More detailed examples can be found at:'
echo http://www.bolthole.com/solaris/zrep/zrep.documentation.html
echo ''
echo 'See the above documentation for details on using the -t flag to use zrep tags'
}
#
# Special global flags that must always be processed FIRST, before normal command args.
#
while [[ "$1" == -[tD] ]] ; do
case "$1" in
-D)
DEBUG=1
shift
;;
-t)
if [ "$2" == "" ] ; then
usage
fi
#deliberately dont quote this to avoid stupidity or malice by user
ZREPTAG=$2
shift
shift
;;
esac
done
if [[ "$ZREPTAG" != "zrep" ]] ; then
# If custom zrep tag, then probably multiple layers of snapshots.
# In this case, DO NOT send all intermediate snapshots for replication
ZREP_INC_FLAG=${ZREP_INC_FLAG:-"-i"}
if [ "$ZREPTAG" != "" ] ; then
ZREP_PATH="$ZREP_PATH -t $ZREPTAG"
fi
fi
# ensure it is set to SOMETHING by default. Default is to send all
ZREP_INC_FLAG=${ZREP_INC_FLAG:-"-I"}
case "$1" in
"")
usage
;;
changeconfig|-C)
shift
zrep_changeconfig "$@"
;;
clear)
shift
# only actually allows ONE fs
if [[ "$1" == "-f" ]] ; then
shift
ZREP_FORCE=-f
fi
zrep_clear "$@"
;;
expire|-e)
shift
zrep_expire "$@"
;;
init|-i)
shift
while [ "$1" != "" ] ; do
case $1 in
"-f")
shift
ZREP_FORCE=-f
;;
"-v")
shift
ZREP_VERBOSE=yes
;;
*)
break
;;
esac
done
zrep_init "$@"
;;
sentsync)
shift
# Note that this will NOT accept multiple snaps, for safety
zrep_sentsync "$@"
;;
snaponly)
shift
zrep_snaponly "$@"
;;
sync|-S) #remember, this is inverse of refresh
shift
while [ "$1" != "" ] ; do
case $1 in
"-f")
shift
ZREP_FORCE=-f
;;
"-v")
shift
ZREP_VERBOSE=yes
;;
"-r")
shift
ZREP_RESUME=yes
;;
*)
break
;;
esac
done
zrep_sync "$@"
;;
synconly)
shift
zrep_synconly "$@"
;;
refresh) # yes keep this in this order
shift
while [ "$1" != "" ] ; do
case $1 in
"-f")
shift
ZREP_FORCE=-f
;;
"-v")
shift
ZREP_VERBOSE=yes
;;
"-r")
shift
ZREP_RESUME=yes
;;
*)
break
;;
esac
done
zrep_refresh "$@"
;;
status|-s)
shift
zrep_status "$@"
;;
list|-l)
shift
zrep_list "$@"
;;
lastsent|getlastsent)
# lastsent is a backward compability hook.
shift
zrep_getlastsent "$@"
;;
failover)
shift
if [[ "$1" == "-f" ]] ; then
shift
ZREP_FORCE=-f
fi
zrep_failover "$@"
;;
setlastsent)
shift
#zrep_setlastsent "$@"
echo Nothing to see here. You might want sentsync. You might not.
# This kind of overlaps with "sentsync". Which may be poorly named
#
exit 1
;;
takeover)
shift
zrep_takeover "$@"
;;
uptodate)
shift
zrep_uptodate "$@"
exit $?
;;
version)
echo "zrep $ZREP_VERSION"
echo "http://www.bolthole.com/solaris/zrep"
echo "http://www.github.com/bolthole/zrep"
exit
;;
_refreshpull) # Secret option DO NOT PUT IN USAGE!!
shift
_refreshpull $@
;;
_refreshcomplete) # Secret option DO NOT PUT IN USAGE!!
shift
_refreshcomplete $@
;;
*)
echo "ERROR: unrecognized zrep subcommand $1"
echo " Dont know what to do with: $0 $@"
echo ""
usage
;;
esac