source: src-sh/lpreserver/lpreserver @ 4f0d211

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

Update the help for cronsnap

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