-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsnebu-client
executable file
·799 lines (686 loc) · 26.1 KB
/
snebu-client
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
#!/bin/bash
# Copyright 2009 - 2021 Derek Pressnall
#
# This file is part of Snebu, the Simple Network Encrypting Backup Utility
#
# Snebu is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License Version 3
# as published by the Free Software Foundation.
#
# Snebu is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Snebu. If not, see <https://www.gnu.org/licenses/>.
process_cmdline()
{
if [ "$1" == "backup" ]
then
target=do_backup
shift
elif [ "$1" == "restore" ]
then
target=do_restore
shift
elif [ "$1" == "validate" ]
then
target=validate
shift
elif [ "$1" == "listbackups" ]
then
target=listbackups
shift
elif [ "$1" == "help" ]
then
usage $2
else
usage
exit
fi
if [ \( "${target}" = "do_backup" -o "${target}" = "do_restore" \) -a -t 1 ]
then
verbose=1
else
verbose=0
fi
if ! args=("$(getopt -l "config:,name:,remote-client:,backup-server:,backup-user:,remote-user:,retention:,date:,force-full,changedir:,exclude:,xmatch:,graft:,plugin:,verbose,quiet,help,sudo:,encryption-key:,decrypt,nodecrypt" -o "c:n:r:d:fqvC:x:m:hk:" -- "$@")")
then
usage target
exit 1
fi
eval set -- "${args[@]}"
while [ -n "$1" ]
do
case $1 in
-c|--config) configfile=$2; shift; shift;;
-n|--name) backupname=$2; shift; shift;;
--remote-client) clientname=$2; shift; shift;;
--backup-server) bksvrname=$2; shift; shift;;
--backup-user) bkuser=$2; shift; shift;;
--remote-user) rmtuser=$2; shift; shift;;
-r|--retention) retention=$2; shift; shift;;
-d|--date) datestamp=$2; shift; shift;;
-f|--force-full) force_full=1; shift;;
-C|--changedir) tgtdirectory=$2; shift; shift;;
--graft) graftdir=$2; shift; shift;;
-x|--exclude) EXCLUDE=( "$2" ); shift; shift;;
-m|--xmatch) EXCLUDEMATCH=( "$2" ); shift; shift;;
--plugin) plugin=$2; shift; shift;;
-h|--help) shift; usage $target;;
-v|--verbose) verbose=$((${verbose} + 1)); shift;;
-q|--quiet) verbose=0; shift;;
--sudo) sudousr=$2; shift; shift;;
-k|--encryption-key) keyfile=( "${keyfile[@]}" "$2"); shift; shift;;
--decrypt) decrypt=1; shift;;
--nodecrypt) nodecrypt=1; shift;;
--) shift; break;;
esac
done
filelist=( "$@" )
# Command line variables trump environment variables, which trump config
# file vars, which trump defaults. Therefore, save cmdline vars for later.
savevars="$(declare -p backupname clientname bksvrname retention datestamp force_full tgtdirectory INCLUDE EXCLUDE EXCLUDEMATCH graftdir plugin 2>/dev/null)"
}
defaults()
{
configfile=${configfile:-~/.snebu-client.conf}
[ ! -f ${configfile} ] && configfile=/etc/snebu-client.conf
[ ! -f ${configfile} ] && configfile=/etc/snebu/snebu-client.conf
SNEBU=snebu
TARCRYPT=tarcrypt
# Need to bring back command line vars, go get config file name override
eval "${savevars}"
# See if we are encrypting
if [ ${#keyfile[@]} -gt 0 ]
then
tarfilter=do_tarencrypt
else
tarfilter=cat
fi
if [ "${decrypt}" == 1 ] && ! type -P tarcrypt >/dev/null 2>&1
then
echo "Error -- decryption specified, but missing tarcrypt executable" >&2
exit 1
fi
if [ "${decrypt}" == 1 ] || ( type -P tarcrypt >/dev/null 2>&1 && [ -z "${nodecrypt}" ] )
then
rtarfilter=do_tardecrypt
else
rtarfilter=cat
fi
# Process configuration file
[ -f "${configfile}" ] && . "${configfile}"
# Now re-process command line vars, as they trump config file.
eval "${savevars}"
# Set the name of the backup to the same as remote client, if backup name
# not specified
if [ -z "${backupname}" -a -n "${clientname}" ]
then
backupname="${clientname}"
fi
if [[ -z "${backupname}" && ( "${target}" = "do_backup" || "${target}" = "restore" ) ]]
then
backupname="$(uname -n)"
fi
# Set default retention schecdule based on date/weekday
if [ ${target} = "do_backup" ]
then
[ -z "${datestamp}" ] && datestamp=$(date +%s)
DAY_OF_WEEK=$(date -d @${datestamp} +%u)
DAY_OF_MONTH=$(date -d @${datestamp} +%d)
if [ -z "${retention}" ]
then
if [ ${DAY_OF_MONTH} = "01" ]
then
retention="monthly"
elif [ ${DAY_OF_WEEK} = "6" ]
then
retention="weekly"
else
retention="daily"
fi
fi
# Set include list
if [ ${#filelist[@]} != 0 ]
then
INCLUDE=( "${filelist[@]}" )
fi
fi
if [ -n "${bksvrname}" ]
then
SNEBU=do_rsnebu
fi
if [ -n "${clientname}" -a -z "${rmtuser}" ]
then
rmtuser="root"
fi
if [ -n "${bksvrname}" -a -z "${bkuser}" ]
then
bkuser="snebu"
fi
if [ -n "${snebu_sshagent_env}" ]
then
snebu_sshagent_env=~/.ssh_backup_agent_env
fi
[ -n "${plugin}" ] && . ${plugin}
}
tartest()
{
declare tarxargs
declare has_acls
declare has_selinux
declare has_blahblah
has_acls=1; has_xattrs=1; has_selinux=1
# tarhelp=$(tar --help)
# echo "${tarhelp}" |grep -- "--acls" >/dev/null 2>&1 && has_acls=1
# echo "${tarhelp}" |grep -- "--xattrs" >/dev/null 2>&1 && has_xattrs=1
# echo "${tarhelp}" |grep -- "--selinux" >/dev/null 2>&1 && has_selinux=1
tarxargs="${has_acls:+--acls} ${has_xattrs:+--xattrs} ${has_selinux:+--selinux}"
echo "${tarxargs}"
}
rsnebu()
{
lzop -d |snebu "${@}" |lzop -f
}
do_rsnebu()
{
lzop |rpcsh -h ${bksvrname} -u ${bkuser} -f rsnebu -m rsnebu -- "${@}" |lzop -d -f
}
usage()
{
if [ -z "$1" ]; then
cat <<-EOT
Usage: snebu-client [ subcommand ] [ options ]
snebu-client is the client front end for snebu. Use it to easily
back up a local or remote host, to either local a local storage
device, or to a remote backup server. Use it with one of the
following subcommands.
Sub commands are as follows:
backup [ -n backupname ] [ -d datestamp ] [ -r schedule ]
restore [ -n backupname ] [ -d datestamp ]
listbackups [ -n backupname [ -d datestamp ]] [ file_list... ]
validate [ -n backupname ] [ -d datestamp ]
help [subcommand]
EOT
elif [ "$1" = "backup" ]; then
cat <<-EOT
Usage: snebu-client backup [ -n backupname ] [ -d datestamp ] [ -r schedule ]
[ file-list ]
Initiates a system backup. By default, it will back up the local
host to a local snebu install. You can also use this command to back
up to a remote backup server, back up a remote host to either a local
snebu instalation, or back up a remote host to another remote backup
server, depending on which options are chosen.
Options:
-c, --config config_file Name of the configuration file. Default is
/etc/snebu-client.conf.
-n, --name backupname Name of the backup. Usually set to the server
name that you are backing up.
-d, --date datestamp Date stamp for this backup set. The format is in
time_t format, sames as the output of the "date
+%s" command.
-r, --retention schedule Retention schedule for this backup set. Typical
values are "daily", "weekly", "monthly", "yearly".
-k, --encryption-key keyfile
Turns on encryption, and specifies encryption
key location. May be specified more than once to
encrypt with multiple keys.
The program "tarcrypt" needs to be present on the
client for this option. Keys are generated with
the command:
tarcrypt genkey -f keyname
-C, --changedir path Changes to the given directory path before
backing up or restoring.
--graft /path/name/=/new/name/
Re-write path names beginning with "/path/name/"
to "/new/name/"
-f, --force-full Force a full backup
--remote-client hostname
Host name / IP address of remote host. Used to
backup a remote host to local backup server.
--remote-user userid
User ID for remote remote-client. Defaults to
root.
--sudo userid
Initial login User ID for remote remote-client.
This ID uses sudo to switch to remote-user once
logged in.
--backup-server hostname
Host name / IP address of backup server. Used to
backup to a remote server.
--backup-user userid
User ID for remote backup-server.
--plugin scriptname Specifies an optional plug in script. Usually
used to perform database-specific operations
(such as enabling hot backup mode) for systems
with a DB installed.
[ file-list ] List of files to backup -- overrides default
EOT
elif [ "$1" = "restore" ]; then
cat <<-EOT
Usage: snebu-client restore [ -n backupname ] [ -d datestamp ] [ file-list ]
Restores a given backup session identified by "-n" and "-d"
parameters. Use the "listbackups" subcommand to get a list of
available backup sessions.
Options:
-c, --config config_file Name of the configuration file. Default is
/etc/snebu-client.conf.
-n, --name backupname Name of the backup. Usually set to the server
name that you are backing up.
-d, --date datestamp Date stamp for this backup set. The format is in
time_t format, sames as the output of the "date
+%s" command.
--decrypt Turns on decryption. Requires "tarcrypt" to be
on the client. Password(s) will be promted for
during restore.
-C, --changedir path Changes to the given directory path before
backing up or restoring.
--graft /path/name/=/new/name/
Re-write path names beginning with "/path/name/"
to "/new/name/"
--remote-client hostname
Host name / IP address of remote host. Used to
backup a remote host to local backup server.
--remote-user userid
User ID for remote remote-client. Defaults to
root.
--sudo userid
Initial login User ID for remote remote-client.
This ID uses sudo to switch to remote-user once
logged in.
--backup-server hostname
Host name / IP address of backup server. Used to
backup to a remote server.
--backup-user userid
User ID for remote backup-server.
[ file-list ] List of files to restore. Defaults to all.
EOT
elif [ "$1" = "validate" ]; then
cat <<-EOT
Usage: snebu-client validate [ -n backupname ] [ -d datestamp ] [ file-list ]
Compares the contents a given backup session identified by "-n" and "-d"
parameters, to what is on the client. Use the "listbackups" subcommand to
get a list of available
backup sessions.
Options:
-c, --config config_file Name of the configuration file. Default is
/etc/snebu-client.conf.
-n, --name backupname Name of the backup. Usually set to the server
name that you are backing up.
-d, --date datestamp Date stamp for this backup set. The format is in
time_t format, sames as the output of the "date
+%s" command.
--decrypt Turns on decryption. Requires "tarcrypt" to be
on the client. Password(s) will be promted for
during restore.
By default, tarcrypt will be called if available
which acts in passthrough mode when processing
unencrypted data.
--nodecrypt Turns off decryption. Will cause unexpected
results if backup contains any encrypted files.
-C, --changedir path Changes to the given directory path before
validating
-x, --exclude "path" Excludes the given path(s)
-m, --xmatch "pattern" Excludes files matching pattern(s)
--remote-client hostname
Host name / IP address of remote host. Used to
backup a remote host to local backup server.
--remote-user userid
User ID for remote remote-client. Defaults to
root.
--sudo userid
Initial login User ID for remote remote-client.
This ID uses sudo to switch to remote-user once
logged in.
--backup-server hostname
Host name / IP address of backup server. Used to
backup to a remote server.
--backup-user userid
User ID for remote backup-server.
[ file-list ] List of files to validate. Defaults to all.
EOT
elif [ "$1" = "listbackups" ]; then
cat <<-EOT
Usage: snebu-client listbackups [ -n hostname [ -d datestamp ]] [ file_list... ]
With no arguments specified, "listbackups" will return a list of all
systems that are contained in the backup catalog. Otherwise, when
specifying the -n parameter, a list of backup sets for that host is
returned.
Options:
-c, --config config_file Name of the configuration file. Default is
/etc/snebu-client.conf.
-n, --name backupname Name of the backup. Usually set to the server
name that you are backing up.
-d, --date datestamp Date stamp for this backup set. The format is in
time_t format, sames as the output of the "date
+%s" command.
EOT
fi
exit
}
main()
{
process_cmdline "$@"
defaults
if [[ -n "${bksvrname}" && ( -n "${client_keyprint}" || -n "${snebu_keyprint}" ) ]]
then
start_agent
fi
if [ -n "${clientname}" ]
then
[ "${target}" = "do_backup" ] && target=do_remote_backup
[ "${target}" = "do_restore" ] && target=do_remote_restore
[ "${target}" = "validate" ] && target=remote_validate
fi
${target} "${filelist[@]}"
}
start_agent() {
if [ -f ${snebu_sshagent_env} ]
then
. ${snebu_sshagent_env} >/dev/null 2>&1
fi
if [ -z "${SSH_AGENT_PID}" ] || ! kill -0 ${SSH_AGENT_PID} >/dev/null 2>&1
then
ssh-agent >${snebu_sshagent_env}
. ${snebu_sshagent_env}
fi
if [ -n "${snebu_keyprint}" -a -n "${snebu_sshkey}" ] && ! ssh-add -l |grep "$snebu_keyprint" >/dev/null 2>&1
then
ssh-add "${snebu_sshkey}"
fi
if [ -n "${client_keyprint}" -a -n "${client_sshkey}" ] && ! ssh-add -l |grep "$client_keyprint" >/dev/null 2>&1
then
ssh-add "${client_sshkey}"
fi
}
autoinclude() {
mount -t $(
grep -v '^nodev' /proc/filesystems |awk '{printf("%s%s", NR != 1 ? "," : "", $NF)}'
) |awk '{print $3}'
}
# rpcsh -- Runs a function on a remote host
# This function pushes out a given set of variables and functions to
# another host via ssh, then runs a given function with optional arguments.
# Usage:
# rpcsh -h remote_host [ -p ssh-port ] -u remote_login -v "variable list" \
# -f "function list" -m mainfunc
#
# The "function list" is a list of shell functions to push to the remote host
# (including the main function to execute, and any functions that it calls)
# Use the "variable list" to send a group of variables to the remote host.
# Finally "mainfunc" is the name of the function (from "function list")
# to execute on the remote side. Any additional parameters specified gets
# passed along to mainfunc.
rpcsh() {
origargs=( "$@" )
declare useretvars retvars
if ! args=("$(getopt -l "rmthost:,rmthostport:,rmtlogin:,pushvars:,pushfuncs:,rmtmain:,retvars:,sudousr:" -o "h:p:u:v:f:m:Ar:s:" -- "$@")")
then
exit 1
fi
sshvars=( -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null )
eval set -- "${args[@]}"
while [ -n "$1" ]
do
case $1 in
-h|--rmthost) rmthost=$2; shift; shift;;
-p|--rmtport) sshvars=( "${sshvars[@]}" -p $2 ); shift; shift;;
-r|--retvars) useretvars=1; retvars=( $2 ); shift; shift;;
-u|--rmtlogin) rmtlogin=$2; shift; shift;;
-v|--pushvars) pushvars=$2; shift; shift;;
-f|--pushfuncs) pushfuncs=$2; shift; shift;;
-m|--rmtmain) rmtmain=$2; shift; shift;;
-s|--sudousr) sudousr=$2; shift; shift;;
-A) sshvars=( "${sshvars[@]}" -A ); shift;;
-i) sshvars=( "${sshvars[@]}" -i $2 ); shift; shift;;
--) shift; break;;
esac
done
rmtargs=( "$@" )
if [ -n "${sudousr}" ]
then
rmtmain=rpcsudo
rmtargs=( "${origargs[@]}" )
pushfuncs="${pushfuncs} rpcsudo"
rmtlogin="${sudousr}"
fi
if [ "${useretvars}" = 1 ]
then
eval $(ssh ${sshvars[@]} ${rmtlogin}@${rmthost} "
$(declare -p rmtargs 2>/dev/null)
$([ -n "$pushvars" ] && declare -p $pushvars 2>/dev/null)
$(declare -f $pushfuncs 2>/dev/null)
$rmtmain \"\${rmtargs[@]}\" >/dev/null 2>&1
for retvar in ${retvars[@]}
do
declare -p \$retvar |sed 's/^declare -a \([^=]*=\)'\''\(.*\)'\''/\1\2/;s/^declare .. //'
done
")
else
ssh ${sshvars[@]} ${rmtlogin}@${rmthost} "
$(declare -p rmtargs 2>/dev/null)
$([ -n "$pushvars" ] && declare -p $pushvars 2>/dev/null)
$(declare -f $pushfuncs 2>/dev/null)
$rmtmain \"\${rmtargs[@]}\"
"
fi
}
rpcsudo() {
declare useretvars retvars
if ! args=("$(getopt -l "rmthost:,rmthostport:,rmtlogin:,pushvars:,pushfuncs:,rmtmain:retvars:" -o "h:p:u:v:f:m:Ar:s:" -- "$@")")
then
exit 1
fi
eval set -- "${args[@]}"
while [ -n "$1" ]
do
case $1 in
-h|--rmthost) shift; shift;;
-p|--rmtport) shift; shift;;
-r|--retvars) useretvars=1; retvars=( $2 ); shift; shift;;
-u|--rmtlogin) rmtlogin=$2; shift; shift;;
-v|--pushvars) pushvars=$2; shift; shift;;
-f|--pushfuncs) pushfuncs=$2; shift; shift;;
-m|--rmtmain) rmtmain=$2; shift; shift;;
-s|--sudousr) sudousr=$2; shift; shift;;
-A) shift;;
-i) shift; shift;;
--) shift; break;;
esac
done
rmtargs=( "$@" )
if [ "${useretvars}" = 1 ]
then
eval $(sudo su - ${rmtlogin} -c "
$(declare -p rmtargs 2>/dev/null)
$([ -n "$pushvars" ] && declare -p $pushvars 2>/dev/null)
$(declare -f $pushfuncs 2>/dev/null)
$rmtmain \"\${rmtargs[@]}\" >/dev/null 2>&1
for retvar in ${retvars[@]}
do
declare -p \$retvar |sed 's/^declare -a \([^=]*=\)'\''\(.*\)'\''/\1\2/;s/^declare .. //'
done
")
else
sudo su - ${rmtlogin} -c "
$(declare -p rmtargs 2>/dev/null)
$([ -n "$pushvars" ] && declare -p $pushvars 2>/dev/null)
$(declare -f $pushfuncs 2>/dev/null)
$rmtmain \"\${rmtargs[@]}\"
"
fi
}
FINDCMD() {
# Printf's used in find commandline
FILE_PATTERN="%y\t%#m\t%D\t%i\t%u\t%U\t%g\t%G\t%s\t0\t%C@\t%T@\t%p\0"
LINK_PATTERN="%y\t%#m\t%D\t%i\t%u\t%U\t%g\t%G\t%s\t0\t%C@\t%T@\t%p\0%l\0"
# Build Find exclude commands from exclude list
for i in "${EXCLUDE[@]}"
do
findexclude=( "${findexclude[@]}" -path "$(echo "$i" |sed "s/\/$//")" -prune -o )
done
for i in "${EXCLUDEMATCH[@]}"
do
findexclude=( "${findexclude[@]}" -path "$i" -o )
done
find "${INCLUDE[@]}" -xdev "${findexclude[@]}" \( -type f -o -type d \) \
-printf "${FILE_PATTERN}" -o -type l -printf "${LINK_PATTERN}"
}
make_include_tempfile()
{
## Attempt to create a secure temp file, fall back to less secure methods
## if mktemp isn't available
includetmp=$(mktemp /tmp/snebu.include.XXXXXXXXXX)
if [ -z "${includetmp}" ]
then
includetmp=/tmp/snebu.include.$RANDOM
fi
if [ -z "${includetmp}" ]
then
includetmp=/tmp/snebu.include.$$
fi
}
do_backup()
{
# Create list of files and metadata to backup, send to Snebu, and
# store received file list in tmp file.
[ -n "${graftdir}" ] && newbackupopts=( "${newbackupopts[@]}" --graft "${graftdir}" )
[ "${force_full}" = 1 ] && newbackupopts=( "${newbackupopts[@]}" --full )
for i in $(seq 1 "${verbose}"); do submitfilesopts=( "${submitfilesopts[@]}" -v ); done
for i in $(seq 1 "${verbose}"); do newbackupopts=( "${newbackupopts[@]}" -v ); done
# Call autoinclude function if INCLUDE is not set
if [ ${#INCLUDE[@]} = 0 ]
then
INCLUDE=( $(autoinclude) )
# And add vault & data catalog directories to EXCLUDE
if [ ${#EXCLUDE[@]} = 0 -a -z "${clientname}" -a -z "${bksvrname}" ]
then
EXCLUDE=( $(
cat /etc/snebu.conf |egrep '^vault|^meta' |cut -d= -f2 |sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//'
) )
fi
fi
bkrepeat=0
while :
do
[ -n "${pluginpre}" ] && $pluginpre
make_include_tempfile
FINDCMD |$SNEBU newbackup --name ${backupname} --retention ${retention} \
--datestamp ${datestamp} --null --not-null-output "${newbackupopts[@]}" |\
cat >${includetmp}
# Now create a tar file and send it to Snebu
tar --one-file-system --no-recursion $(tartest) -S -P -T ${includetmp} -cf - |\
$tarfilter |\
$SNEBU submitfiles --name ${backupname} --datestamp ${datestamp} "${submitfilesopts[@]}"
rm -f ${includetmp}
[ -n "${pluginpost}" ] && $pluginpost
if [ "${bkrepeat}" != 1 ]
then
break
fi
done
}
do_remote_backup()
{
# Create list of files and metadata to backup, send to Snebu, and
# store received file list in tmp file.
[ -n "${graftdir}" ] && newbackupopts=( "${newbackupopts[@]}" --graft "${graftdir}" )
[ "${force_full}" = 1 ] && newbackupopts=( "${newbackupopts[@]}" --full )
for i in $(seq 1 "${verbose}"); do submitfilesopts=( "${submitfilesopts[@]}" -v ); done
for i in $(seq 1 "${verbose}"); do newbackupopts=( "${newbackupopts[@]}" -v ); done
# Call autoinclude function if INCLUDE is not set
[ ${#INCLUDE[@]} = 0 ] && INCLUDE=( $(rpcsh -h ${clientname} -u "${rmtuser}" -f autoinclude -m autoinclude) )
bkrepeat=0
while :
do
## Run plugin pre function
[ -n "${pluginpre}" ] && $pluginpre
rpcsh -h ${clientname} -u "${rmtuser}" -f 'make_include_tempfile' \
-r 'includetmp' -m 'make_include_tempfile'
rpcsh -h ${clientname} -u "${rmtuser}" -f FINDCMD -v "INCLUDE EXCLUDE EXCLUDEMATCH" -m FINDCMD |\
$SNEBU newbackup --name ${backupname} --retention ${retention} \
--datestamp ${datestamp} --null --not-null-output "${newbackupopts[@]}" |\
rpcsh -h ${clientname} -u "${rmtuser}" -m "cat >${includetmp}"
# Now create a tar file and send it to Snebu
rpcsh -h ${clientname} -u "${rmtuser}" -v "TARCRYPT keyfile" -f "tartest do_tarencrypt" -m "tar --one-file-system --no-recursion $(tartest) -S -P -T ${includetmp} -cf - |${tarfilter} |lzop" |\
lzop -d |$SNEBU submitfiles --name ${backupname} --datestamp ${datestamp} "${submitfilesopts[@]}"
rpcsh -h ${clientname} -u "${rmtuser}" -m "rm -f ${includetmp}"
## Run plugin post function
[ -n "${pluginpost}" ] && $pluginpost
## If plugin post function needs to back up addtional files, it sets bkrepeat on
if [ "${bkrepeat}" != 1 ]
then
break
fi
bkrepeat=0
done
}
do_restore()
{
[ -n "${graftdir}" ] && restoreopts=( "${restoreopts[@]}" --graft "${graftdir}" )
if [ -n "${tgtdirectory}" ]
then
tarargs=( "${tarargs[@]}" -C $tgtdirectory )
fi
$SNEBU restore --name ${backupname} --datestamp ${datestamp} "${restoreopts[@]}" "${@}" </dev/null |${rtarfilter} |tar "${tarargs[@]}" $(tartest) -xvf -
}
do_remote_restore()
{
if [ -n "${tgtdirectory}" ]
then
tarargs=( "${tarargs[@]}" -C $tgtdirectory )
fi
$SNEBU restore --name ${backupname} --datestamp ${datestamp} "${@}" </dev/null |\
rtarfilter |\
rpcsh -h ${clientname} -u "${rmtuser}" -m "tar ${tarargs[*]} $(tartest) -xvf -"
}
validate()
{
[ -n "${graftdir}" ] && restoreopts=( "${restoreopts[@]}" --graft "${graftdir}" )
if [ -n "${tgtdirectory}" ]
then
tarargs=( "${tarargs[@]}" -C $tgtdirectory )
fi
$SNEBU restore --name ${backupname} --datestamp ${datestamp} "${restoreopts[@]}" "${@}" </dev/null |${rtarfilter} |tar "${tarargs[@]}" $(tartest) -df - &&
echo "No errors found"
}
remote_validate()
{
if [ -n "${tgtdirectory}" ]
then
tarargs=( "${tarargs[@]}" -C $tgtdirectory )
fi
$SNEBU restore --name ${backupname} --datestamp ${datestamp} "${@}" </dev/null |\
rtarfilter |\
rpcsh -h ${clientname} -u "${rmtuser}" -f tartest -m "tar ${tarargs[*]} $(tartest) -df - && echo \"No errors found\""
}
listbackups()
{
[ -n "${backupname}" ] && sargs=( "${sargs[@]}" -n ${backupname} )
[ -n "${datestamp}" ] && sargs=( "${sargs[@]}" -d ${datestamp} )
if [ -z "${backupname}" -a "${verbose}" -ge 1 ]
then
for i in $( $SNEBU listbackups </dev/null)
do
$SNEBU listbackups -n $i </dev/null
done
else
$SNEBU listbackups "${sargs[@]}" "${@}" </dev/null
fi
}
do_tarencrypt()
{
tarcrypt_args=( encrypt )
for i in "${keyfile[@]}"
do
tarcrypt_args=( "${tarcrypt_args[@]}" -k $i )
done
$TARCRYPT "${tarcrypt_args[@]}"
}
do_tardecrypt()
{
$TARCRYPT decrypt
}
main "${@}"