~m-grant-prg/lixbackups/jammy-trunk

« back to all changes in this revision

Viewing changes to src/prg/bash/netbckup.sh.in

  • Committer: Mark Grant
  • Date: 2020-01-14 10:40:22 UTC
  • mfrom: (1.1.36)
  • Revision ID: m.grant.prg@gmail.com-20200114104022-cx4eop3e91bfnw3n
Merge new upstream development release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#########################################################################
10
10
#                                                                       #
11
11
# Script ID: netbckup                                                   #
12
 
# Author: Copyright (C) 2012-2019  Mark Grant                           #
 
12
# Author: Copyright (C) 2012-2020  Mark Grant                           #
13
13
#                                                                       #
14
14
# Released under the GPLv3 only.                                        #
15
15
# SPDX-License-Identifier: GPL-3.0                                      #
146
146
# 18/03/2019    MG      1.3.2   Fix globbing of trashbox emptying.      #
147
147
# 19/04/2019    MG      1.3.3   Replace obsolete backticks with $(cmd). #
148
148
# 09/08/2019    MG      1.3.4   Correct getopt CL for proper quoting.   #
 
149
# 11/10/2019    MG      1.3.5   Move std_cmd_err_handler() before it is #
 
150
#                               used.                                   #
 
151
#                               Move script_exit() before it is used.   #
 
152
# 14/01/2020    MG      1.3.6   Use no-check-device when performing any #
 
153
#                               listed-incremental operation. (See      #
 
154
#                               in-line comment for reasoning).         #
149
155
#                                                                       #
150
156
#########################################################################
151
157
 
154
160
##################
155
161
readonly outputprefix="$(basename $0):"
156
162
 
157
 
readonly version=1.3.4                          # Script version
 
163
readonly version=1.3.6                          # Script version
158
164
readonly packageversion=@pkgversion@            # Package version
159
165
 
160
166
readonly etclocation=@sysconfdir@/lixbackups    # Path to config directory
188
194
EOF
189
195
}
190
196
 
191
 
# Standard function to emit messages depending on various parameters.
192
 
# Parameters -  $1 What:-       The message to emit.
193
 
#               $2 Where:-      stdout == 0
194
 
#                               stderr != 0
195
 
#               $3 Syslog:-     $3 == 0, No.
196
 
#                               $3 != 0, Yes.
197
 
# No return value.
198
 
output()
199
 
{
200
 
        if (( !$2 )); then
201
 
                printf "%s %s %s\n" "$(date +'[ %a %b %d %T ]')" $outputprefix \
202
 
                        "$1"
203
 
        else
204
 
                printf "%s %s %s\n" "$(date +'[ %a %b %d %T ]')" $outputprefix \
205
 
                        "$1" 1>&2
206
 
        fi
207
 
        if (( $3 )); then
208
 
                logger "$outputprefix $1"
209
 
                std_cmd_err_handler $?
210
 
        fi
211
 
}
212
 
 
213
 
# Standard function to test command error and exit if non-zero.
214
 
# Parameters - $1 is $?
215
 
# No return value.
216
 
std_cmd_err_handler()
217
 
{
218
 
        if (( $1 )); then
219
 
                script_exit $1
220
 
        fi
221
 
}
222
 
 
223
197
# Standard function to tidy up and return exit code.
224
198
# Parameters -  $1 is the exit code.
225
199
# No return value.
254
228
        exit $1
255
229
}
256
230
 
 
231
# Standard function to test command error and exit if non-zero.
 
232
# Parameters - $1 is $?
 
233
# No return value.
 
234
std_cmd_err_handler()
 
235
{
 
236
        if (( $1 )); then
 
237
                script_exit $1
 
238
        fi
 
239
}
 
240
 
 
241
# Standard function to emit messages depending on various parameters.
 
242
# Parameters -  $1 What:-       The message to emit.
 
243
#               $2 Where:-      stdout == 0
 
244
#                               stderr != 0
 
245
#               $3 Syslog:-     $3 == 0, No.
 
246
#                               $3 != 0, Yes.
 
247
# No return value.
 
248
output()
 
249
{
 
250
        if (( !$2 )); then
 
251
                printf "%s %s %s\n" "$(date +'[ %a %b %d %T ]')" $outputprefix \
 
252
                        "$1"
 
253
        else
 
254
                printf "%s %s %s\n" "$(date +'[ %a %b %d %T ]')" $outputprefix \
 
255
                        "$1" 1>&2
 
256
        fi
 
257
        if (( $3 )); then
 
258
                logger "$outputprefix $1"
 
259
                std_cmd_err_handler $?
 
260
        fi
 
261
}
 
262
 
257
263
# Standard trap exit function.
258
264
# No parameters.
259
265
# No return value.
675
681
                bckupCL+="--exclude-from=$etclocation/bckdaily.exclude "
676
682
                # Exclude system and cache directories
677
683
                bckupCL_add_std_excl
678
 
                bckupCL+="--listed-incremental=$snarpath "
 
684
                # --listed-incremental, by default, stores the device number in
 
685
                # the snar file. Some file systems, perhaps particularly NFS, do
 
686
                # not consistently use the same device number for the same mount
 
687
                # operation. If this happens then a device number mismatch leads
 
688
                # to a full backup. So, do not check the device numbers.
 
689
                bckupCL+="--listed-incremental=$snarpath --no-check-device "
679
690
                ;;
680
691
        fulladhoc)
681
692
                # Build the backup file name and path
700
711
                bckupCL+="$backpath "
701
712
                bckupCL+="--exclude-from=$etclocation/bckdaily.exclude "
702
713
                bckupCL_add_std_excl
703
 
                bckupCL+="--listed-incremental=$snarpath "
 
714
                bckupCL+="--listed-incremental=$snarpath --no-check-device "
704
715
                ;;
705
716
        selective)
706
717
                # Build the backup file name and path
725
736
                bckupCL+="$backpath "
726
737
                bckupCL+="--exclude-from=$etclocation/bckweekly.exclude "
727
738
                bckupCL_add_std_excl
728
 
                bckupCL+="--listed-incremental=$snarpath "
 
739
                bckupCL+="--listed-incremental=$snarpath --no-check-device "
729
740
                ;;
730
741
        esac
731
742