source: src-sh/lpreserver/lpreserver @ 5cc3d00

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 5cc3d00 was 5cc3d00, checked in by Kris Moore <kris@…>, 13 months ago

Add help text for get/set

  • Property mode set to 100755
File size: 8.3 KB
Line 
1#!/bin/sh
2# Command-line interaction script for life-preserver
3# Author: Kris Moore
4# License: BSD
5# "Life-Preserver" Copyright 2013 PC-BSD Software (iXsystems)
6######################################################################
7
8# Source external functions
9. /usr/local/share/pcbsd/scripts/functions.sh
10
11require_root() 
12{
13  UTEST="`whoami`"
14  if [ "$UTEST" != "root" ] ; then
15     exit_err "This command must be run as root!"
16  fi
17}
18
19# Source our functions
20PROGDIR="/usr/local/share/lpreserver"
21
22# Source our local functions
23. ${PROGDIR}/backend/functions.sh
24
25title()
26{
27  echo "Life-Preserver
28---------------------------------"
29};
30
31
32# Function to display help information
33help_main()
34{
35  title
36  echo "Available commands
37
38Type in help <command> for information and usage about that command
39
40       help - This help file"
41
42if [ -e "/usr/local/bin/life-preserver" ] ; then
43   echo "        gui - Launch the GUI"
44fi
45
46cat<<__EOF__
47        get - Get list of lpreserver options
48     mksnap - Create a ZFS snapshot of a zpool/dataset
49   listsnap - List snapshots of a zpool/dataset
50   listcron - Listing of scheduled snapshots
51   cronsnap - Schedule snapshot creation via cron
52 revertsnap - Revert zpool/dataset to a snapshot
53  replicate - Enable / Disable ZFS replication to a remote system
54        set - Set lpreserver options
55     status - List datasets, along with last snapshot / replication date
56     rmsnap - Remove a snapshot
57__EOF__
58};
59
60help_replicate()
61{
62 title
63 echo "Help replicate
64
65Life-Preserver replication sub-system
66
67Replication uses ZFS to send your snapshots to a remote system which also has
68a ZFS pool, such as FreeNAS or another PC-BSD system. The <hostdataset> must
69also be scheduled for snapshots for replication to occur.
70
71On the remote system, you will need to have created the <remotedataset> beforehand.
72
73If you plan to replicate to a non-root user, please set the following permissions
74on the remote dataset:
75
76# zfs allow -u <user> create,receive,mount,userprop,destroy,send,hold <remotedataset>
77
78Available Flags:
79        list - List replication targets
80         add - Add a new replication target
81      remove - Remove a replication target
82
83Add Options:
84
85        add <remotehost> <user> <port> <hostdataset> <remotedataset> <time>
86
87        Example 1:
88
89        add freenas.8343 backupuser 22 tank1/usr/home/kris tankbackup/backups sync
90
91        Will schedule replication of tank1/usr/home/kris to tankbackup/backups with each snapshot
92
93        Example 2:
94
95        add freenas.8343 backupuser 22 tank1 tankbackup/backups 22
96
97        Will schedule replication of tank1 to tankbackup/backups at 10PM, notated in 24hour time
98
99Remove Options:
100
101        remove <dataset>
102       
103        Remove a replication task indicated by <dataset>
104        Use 'replicate list' for a list of IDs.
105
106Usage:
107
108  lpreserver replicate <subcmd> <flags>
109
110Example:
111
112  lpreserver replicate
113"
114};
115
116
117help_set()
118{
119 title
120 echo "Help set
121
122Set Life-Preserver options
123
124Usage:
125
126  lpreserver set
127
128Config options
129
130     duwarn - Set to a disk percentage [0-99] at which to warn of low disk space
131
132      email - Set the e-mail address to receive notifications
133                This will require that the \"mail\" command is setup for outgoing mail
134
135  emailopts - (ALL/WARN/ERROR)
136                  ALL - Send mail for every snapshot, plus warnings and errors
137                 WARN - Send mail for warnings and errors (Default)
138                ERROR - Send mail for errors only
139
140  recursive - (ON/OFF)
141                   ON - Will create / destroy snapshots recursively, for all children of
142                        a target zpool/dataset. (Default)
143                  OFF - Will only create / destroy snapshots on the specified dataset. 
144
145Example:
146
147  lpreserver set email "kris@example.org,admin@example.org"
148
149  lpreserver set emailopts ALL
150"
151};
152
153help_get()
154{
155 title
156 echo "Help get
157
158Listing of Life-Preserver options set
159
160Usage:
161
162  lpreserver get
163
164Example:
165
166  lpreserver get
167"
168};
169
170help_listcron()
171{
172 title
173 echo "Help listcron
174
175List scheduled cron snapshots
176
177Usage:
178
179  lpreserver listcron
180"
181};
182
183help_status()
184{
185 title
186 echo "Help status
187
188List monitored dataset's last snapshot and replication
189
190Usage:
191
192  lpreserver status
193
194"
195};
196
197
198help_listsnap()
199{
200 title
201 echo "Help listsnap
202
203List ZFS snapshots of a dataset
204
205Usage:
206
207  lpreserver listsnap <dataset>
208
209Example:
210
211  lpreserver listsnap tank0/usr/home/kris
212"
213};
214
215help_cronsnap()
216{
217 title
218 echo "Help cronsnap
219
220Schedule a ZFS snapshot
221
222Usage:
223
224  For a listing of all scheduled snapshots
225
226  # lpreserver listcron
227
228  or
229
230  To start / stop snapshot scheduling
231
232  # lpreserver cronsnap <dataset> <action> <frequency> <numToKeep>
233 
234  action = start / stop
235  frequency = daily@XX / hourly / 30min / 10min / 5min
236                    ^^ Hour to execute
237  numToKeep = Number of snapshots to keep total
238
239Example:
240
241  lpreserver cronsnap tank1/usr/home/kris start daily@22 10
242
243  or
244
245  lpreserver cronsnap tank1/usr/home/kris stop
246"
247};
248
249help_revertsnap()
250{
251 title
252 echo "Help revertsnap
253
254Revert ZFS to a snapshot of a dataset
255
256Usage:
257
258  lpreserver revertsnap <dataset> <SNAP>
259
260Example:
261
262  lpreserver revertsnap tank1/usr/home/kris 20130729-140510
263"
264};
265
266help_rmsnap()
267{
268 title
269 echo "Help rmsnap
270
271Remove ZFS snapshot of a dataset
272
273Usage:
274
275  lpreserver rmsnap <dataset> <SNAP>
276
277Example:
278
279  lpreserver rmsnap tank1/usr/home/kris 20130729-140510
280
281NOTE:
282By default snapshots are recursive and will remove snapshots
283of all children datasets automatically. To change this use:
284
285# lpreserver set recursive off
286"
287};
288
289
290help_mksnap()
291{
292 title
293 echo "Help mksnap
294
295Create a new ZFS snapshot of a dataset
296
297Usage:
298
299  lupdate mksnap <dataset>
300
301Example:
302
303  lupdate mksnap tank1/usr/home/kris
304
305NOTE:
306By default snapshots are recursive and will create snapshots
307of all children datasets automatically. To change this use:
308
309# lpreserver set recursive off
310"
311};
312
313# Check if we need to enable the zfs monitor
314enable_watcher
315
316# Check what the user wants to do
317case "$1" in
318
319   help) case "$2" in
320           get) help_get ;;
321           set) help_set ;;
322           mksnap) help_mksnap ;;
323           listcron) help_listcron ;;
324           listsnap) help_listsnap ;;
325           revertsnap) help_revertsnap ;;
326           replicate) help_replicate ;;
327           cronsnap) help_cronsnap ;;
328           rmsnap) help_rmsnap ;;
329           status) help_status ;;
330           *) help_main ;;
331         esac  ;;
332
333    get) require_root
334         # Display our options 
335         title
336         echo "      Recursive mode: $RECURMODE"
337         echo "E-mail notifications: $EMAILMODE"
338         echo "    E-mail addresses: $EMAILADDY"
339         echo "  Disk space warn at: ${DUWARN}%"
340         exit 0
341         ;;
342
343    set) require_root
344         OPT="${2}" 
345
346         case $OPT in
347        emailopts) case $3 in
348                  ALL|WARN|ERROR) echo "E-Mail mode set to: $3" 
349                                  echo "$3" > ${DBDIR}/emaillevel ;;
350                     *) exit_err "Unknown option" ;;
351                   esac
352                   ;;
353            email) echo "Setting email notification to: $3" 
354                   echo "$3" > ${DBDIR}/emails ;;
355           duwarn) if [ ! $(is_num "$3") ] ; then exit_err "Invalid number, must be 0-99"; fi
356                   echo "Setting disk warning capacity to: ${3}%" 
357                   echo "$3" > ${DBDIR}/duwarn ;;
358        recursive) case $3 in
359                  OFF|Off|off)  echo "Recursive mode disabled" 
360                                touch ${DBDIR}/recursive-off ;;
361                     ON|On|on)  echo "Recursive mode enabled" 
362                                rm ${DBDIR}/recursive-off 2>/dev/null ;;
363                     *) exit_err "Unknown option" ;;
364                   esac
365                   ;;
366                *) exit_err "Invalid option!" ;;
367           esac
368         ;;
369
370   mksnap) require_root
371         DATASET="$2"
372         ${PROGDIR}/backend/zfsmksnap.sh "${DATASET}"
373         ;;
374
375 listcron) require_root
376         ${PROGDIR}/backend/zfslistcron.sh
377         ;;
378
379 listsnap) require_root
380         DATASET="$2"
381         ${PROGDIR}/backend/zfslistsnap.sh "${DATASET}"
382         ;;
383
384 cronsnap) require_root
385         DATASET="$2"
386         ${PROGDIR}/backend/zfscronsnap.sh "${DATASET}" "$3" "$4" "$5"
387         ;;
388
389revertsnap) require_root
390         DATASET="$2"
391         SNAP="$3"
392         ${PROGDIR}/backend/zfsrevertsnap.sh "${DATASET}" "$SNAP"
393         ;;
394
395    rmsnap) require_root
396         DATASET="$2"
397         SNAP="$3"
398         ${PROGDIR}/backend/zfsrmsnap.sh "${DATASET}" "${SNAP}"
399         ;;
400    status) listStatus
401         ;;
402 replicate) require_root
403            shift
404            case ${1} in
405                add) add_rep_task "$2" "$3" "$4" "$5" "$6" "$7" ;;
406                list) list_rep_task ;;
407                remove) cat ${REPCONF} | grep -q "^${2}:" 
408                        if [ $? -eq 0 ] ; then
409                           rem_rep_task "$2"
410                           echo "Removed replication task for $2"
411                        else
412                           exit_err "No such replication task for dataset $2"
413                        fi
414                        ;;
415                *) exit_err "Invalid option!" ;;
416            esac
417         ;;
418   *) help_main ;;
419esac
420
421exit 0
Note: See TracBrowser for help on using the repository browser.