source: src-sh/lpreserver/lpreserver @ 3c8d32d

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

Remove obsolete gui flag from lpreserver

  • Property mode set to 100755
File size: 8.6 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
37cat<<__EOF__
38Available commands
39
40Type in help <command> for information and usage about that command
41
42        get - Get list of lpreserver options
43       help - This help file
44     mksnap - Create a ZFS snapshot of a zpool/dataset
45   listsnap - List snapshots of a zpool/dataset
46   listcron - Listing of scheduled snapshots
47   cronsnap - Schedule snapshot creation via cron
48 revertsnap - Revert zpool/dataset to a snapshot
49  replicate - Enable / Disable ZFS replication to a remote system
50        set - Set lpreserver options
51     status - List datasets, along with last snapshot / replication date
52     rmsnap - Remove a snapshot
53__EOF__
54};
55
56help_replicate()
57{
58 title
59 echo "Help replicate
60
61Life-Preserver replication sub-system
62
63Replication uses ZFS to send your snapshots to a remote system which also has
64a ZFS pool, such as FreeNAS or another PC-BSD system. The <hostdataset> must
65also be scheduled for snapshots for replication to occur.
66
67On the remote system, you will need to have created the <remotedataset> beforehand.
68
69If you plan to replicate to a non-root user, please set the following permissions
70on the remote dataset:
71
72# zfs allow -u <user> create,receive,mount,userprop,destroy,send,hold <remotedataset>
73
74Available Flags:
75        list - List replication targets
76         add - Add a new replication target
77      remove - Remove a replication target
78
79Add Options:
80
81        add <remotehost> <user> <port> <hostdataset> <remotedataset> <time>
82
83        Example 1:
84
85        add freenas.8343 backupuser 22 tank1/usr/home/kris tankbackup/backups sync
86
87        Will schedule replication of tank1/usr/home/kris to tankbackup/backups with each snapshot
88
89        Example 2:
90
91        add freenas.8343 backupuser 22 tank1 tankbackup/backups 22
92
93        Will schedule replication of tank1 to tankbackup/backups at 10PM, notated in 24hour time
94
95Remove Options:
96
97        remove <dataset>
98       
99        Remove a replication task indicated by <dataset>
100        Use 'replicate list' for a list of IDs.
101
102Usage:
103
104  lpreserver replicate <subcmd> <flags>
105
106Example:
107
108  lpreserver replicate
109"
110};
111
112
113help_set()
114{
115 title
116 echo "Help set
117
118Set Life-Preserver options
119
120Usage:
121
122  lpreserver set
123
124Config options
125
126     duwarn - Set to a disk percentage [0-99] at which to warn of low disk space
127
128      email - Set the e-mail address to receive notifications
129                This will require that the \"mail\" command is setup for outgoing mail
130
131  emailopts - (ALL/WARN/ERROR)
132                  ALL - Send mail for every snapshot, plus warnings and errors
133                 WARN - Send mail for warnings and errors (Default)
134                ERROR - Send mail for errors only
135
136  recursive - (ON/OFF)
137                   ON - Will create / destroy snapshots recursively, for all children of
138                        a target zpool/dataset. (Default)
139                  OFF - Will only create / destroy snapshots on the specified dataset. 
140
141Example:
142
143  lpreserver set email "kris@example.org,admin@example.org"
144
145  lpreserver set emailopts ALL
146"
147};
148
149help_get()
150{
151 title
152 echo "Help get
153
154Listing of Life-Preserver options set
155
156Usage:
157
158  lpreserver get
159
160Example:
161
162  lpreserver get
163"
164};
165
166help_listcron()
167{
168 title
169 echo "Help listcron
170
171List scheduled cron snapshots
172
173Usage:
174
175  lpreserver listcron
176"
177};
178
179help_status()
180{
181 title
182 echo "Help status
183
184List monitored dataset's last snapshot and replication
185
186Usage:
187
188  lpreserver status
189
190"
191};
192
193
194help_listsnap()
195{
196 title
197 echo "Help listsnap
198
199List ZFS snapshots of a dataset
200
201Usage:
202
203  lpreserver listsnap <dataset>
204
205Example:
206
207  lpreserver listsnap tank0/usr/home/kris
208"
209};
210
211help_cronsnap()
212{
213 title
214 echo "Help cronsnap
215
216Schedule a ZFS snapshot
217
218Usage:
219
220  For a listing of all scheduled snapshots
221
222  # lpreserver listcron
223
224  or
225
226  To start / stop snapshot scheduling
227
228  # lpreserver cronsnap <dataset> <action> <frequency> <numToKeep>
229 
230  action = start / stop
231  frequency = daily@XX / hourly / 30min / 10min / 5min
232                    ^^ Hour to execute
233  numToKeep = Number of snapshots to keep total
234
235Example:
236
237  lpreserver cronsnap tank1/usr/home/kris start daily@22 10
238
239  or
240
241  lpreserver cronsnap tank1/usr/home/kris stop
242"
243};
244
245help_revertsnap()
246{
247 title
248 echo "Help revertsnap
249
250Revert ZFS to a snapshot of a dataset
251
252Usage:
253
254  lpreserver revertsnap <dataset> <SNAP>
255
256Example:
257
258  lpreserver revertsnap tank1/usr/home/kris 20130729-140510
259"
260};
261
262help_rmsnap()
263{
264 title
265 echo "Help rmsnap
266
267Remove ZFS snapshot of a dataset
268
269Usage:
270
271  lpreserver rmsnap <dataset> <SNAP>
272
273Example:
274
275  lpreserver rmsnap tank1/usr/home/kris 20130729-140510
276
277NOTE:
278By default snapshots are recursive and will remove snapshots
279of all children datasets automatically. To change this use:
280
281# lpreserver set recursive off
282"
283};
284
285
286help_mksnap()
287{
288 title
289 echo "Help mksnap
290
291Create a new ZFS snapshot of a dataset and optionally replicate it immediately
292
293Usage:
294
295  lpreserver mksnap --replicate <dataset> <snapshotname>
296
297Example:
298
299  lpreserver mksnap tank1/usr/home/kris mysnapshot
300
301  or
302
303  lpreserver mksnap --replicate tank1/usr/home/kris mysnapshot
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         if [ "$2" = "--replicate" ] ; then
372           REP="YES"
373           DATASET="$3"
374           SNAPNAME="$4"
375         else
376           REP="NO"
377           DATASET="$2"
378           SNAPNAME="$3"
379         fi
380         ${PROGDIR}/backend/zfsmksnap.sh "${DATASET}" "$SNAPNAME" "$REP"
381         ;;
382
383 listcron) require_root
384         ${PROGDIR}/backend/zfslistcron.sh
385         ;;
386
387 listsnap) require_root
388         DATASET="$2"
389         ${PROGDIR}/backend/zfslistsnap.sh "${DATASET}"
390         ;;
391
392 cronsnap) require_root
393         DATASET="$2"
394         ${PROGDIR}/backend/zfscronsnap.sh "${DATASET}" "$3" "$4" "$5"
395         ;;
396
397revertsnap) require_root
398         DATASET="$2"
399         SNAP="$3"
400         ${PROGDIR}/backend/zfsrevertsnap.sh "${DATASET}" "$SNAP"
401         ;;
402
403    rmsnap) require_root
404         DATASET="$2"
405         SNAP="$3"
406         ${PROGDIR}/backend/zfsrmsnap.sh "${DATASET}" "${SNAP}"
407         ;;
408    status) listStatus
409         ;;
410 replicate) require_root
411            shift
412            case ${1} in
413                add) add_rep_task "$2" "$3" "$4" "$5" "$6" "$7" ;;
414                list) list_rep_task ;;
415                remove) cat ${REPCONF} | grep -q "^${2}:" 
416                        if [ $? -eq 0 ] ; then
417                           rem_rep_task "$2"
418                           echo "Removed replication task for $2"
419                        else
420                           exit_err "No such replication task for dataset $2"
421                        fi
422                        ;;
423                *) exit_err "Invalid option!" ;;
424            esac
425         ;;
426   *) help_main ;;
427esac
428
429exit 0
Note: See TracBrowser for help on using the repository browser.