source: src-sh/lpreserver/lpreserver @ aac00e0

9.2-releasereleng/10.0releng/10.0.1
Last change on this file since aac00e0 was aac00e0, checked in by Kris Moore <kris@…>, 8 months ago

Add --replicate option to "mksnap" to force immediate replication

  • Property mode set to 100755
File size: 8.7 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 and optionally replicate it immediately
296
297Usage:
298
299  lpreserver mksnap --replicate <dataset> <snapshotname>
300
301Example:
302
303  lpreserver mksnap tank1/usr/home/kris mysnapshot
304
305  or
306
307  lpreserver mksnap --replicate tank1/usr/home/kris mysnapshot
308
309NOTE:
310By default snapshots are recursive and will create snapshots
311of all children datasets automatically. To change this use:
312
313# lpreserver set recursive off
314"
315};
316
317# Check if we need to enable the zfs monitor
318enable_watcher
319
320# Check what the user wants to do
321case "$1" in
322
323   help) case "$2" in
324           get) help_get ;;
325           set) help_set ;;
326           mksnap) help_mksnap ;;
327           listcron) help_listcron ;;
328           listsnap) help_listsnap ;;
329           revertsnap) help_revertsnap ;;
330           replicate) help_replicate ;;
331           cronsnap) help_cronsnap ;;
332           rmsnap) help_rmsnap ;;
333           status) help_status ;;
334           *) help_main ;;
335         esac  ;;
336
337    get) require_root
338         # Display our options 
339         title
340         echo "      Recursive mode: $RECURMODE"
341         echo "E-mail notifications: $EMAILMODE"
342         echo "    E-mail addresses: $EMAILADDY"
343         echo "  Disk space warn at: ${DUWARN}%"
344         exit 0
345         ;;
346
347    set) require_root
348         OPT="${2}" 
349
350         case $OPT in
351        emailopts) case $3 in
352                  ALL|WARN|ERROR) echo "E-Mail mode set to: $3" 
353                                  echo "$3" > ${DBDIR}/emaillevel ;;
354                     *) exit_err "Unknown option" ;;
355                   esac
356                   ;;
357            email) echo "Setting email notification to: $3" 
358                   echo "$3" > ${DBDIR}/emails ;;
359           duwarn) if [ ! $(is_num "$3") ] ; then exit_err "Invalid number, must be 0-99"; fi
360                   echo "Setting disk warning capacity to: ${3}%" 
361                   echo "$3" > ${DBDIR}/duwarn ;;
362        recursive) case $3 in
363                  OFF|Off|off)  echo "Recursive mode disabled" 
364                                touch ${DBDIR}/recursive-off ;;
365                     ON|On|on)  echo "Recursive mode enabled" 
366                                rm ${DBDIR}/recursive-off 2>/dev/null ;;
367                     *) exit_err "Unknown option" ;;
368                   esac
369                   ;;
370                *) exit_err "Invalid option!" ;;
371           esac
372         ;;
373
374   mksnap) require_root
375         if [ "$2" = "--replicate" ] ; then
376           REP="YES"
377           DATASET="$3"
378           SNAPNAME="$4"
379         else
380           REP="NO"
381           DATASET="$2"
382           SNAPNAME="$3"
383         fi
384         ${PROGDIR}/backend/zfsmksnap.sh "${DATASET}" "$SNAPNAME" "$REP"
385         ;;
386
387 listcron) require_root
388         ${PROGDIR}/backend/zfslistcron.sh
389         ;;
390
391 listsnap) require_root
392         DATASET="$2"
393         ${PROGDIR}/backend/zfslistsnap.sh "${DATASET}"
394         ;;
395
396 cronsnap) require_root
397         DATASET="$2"
398         ${PROGDIR}/backend/zfscronsnap.sh "${DATASET}" "$3" "$4" "$5"
399         ;;
400
401revertsnap) require_root
402         DATASET="$2"
403         SNAP="$3"
404         ${PROGDIR}/backend/zfsrevertsnap.sh "${DATASET}" "$SNAP"
405         ;;
406
407    rmsnap) require_root
408         DATASET="$2"
409         SNAP="$3"
410         ${PROGDIR}/backend/zfsrmsnap.sh "${DATASET}" "${SNAP}"
411         ;;
412    status) listStatus
413         ;;
414 replicate) require_root
415            shift
416            case ${1} in
417                add) add_rep_task "$2" "$3" "$4" "$5" "$6" "$7" ;;
418                list) list_rep_task ;;
419                remove) cat ${REPCONF} | grep -q "^${2}:" 
420                        if [ $? -eq 0 ] ; then
421                           rem_rep_task "$2"
422                           echo "Removed replication task for $2"
423                        else
424                           exit_err "No such replication task for dataset $2"
425                        fi
426                        ;;
427                *) exit_err "Invalid option!" ;;
428            esac
429         ;;
430   *) help_main ;;
431esac
432
433exit 0
Note: See TracBrowser for help on using the repository browser.