]> arthur.barton.de Git - backup-script.git/commitdiff
backup-script: Implement "-x"/"--no-exec" command line option
authorAlexander Barton <alex@barton.de>
Fri, 21 Oct 2016 10:25:14 +0000 (12:25 +0200)
committerAlexander Barton <alex@barton.de>
Fri, 21 Oct 2016 10:33:43 +0000 (12:33 +0200)
When this option is given, neither the global "setup-exec", "pre-exec",
nor the global "post-exec" coammds will be run.

README.md
bin/backup-script

index 6aa60264aadb33a77796ebdbf8781f93ff825ab8..b74257c1be2e425935a4ce845d62919fb1d012bf 100644 (file)
--- a/README.md
+++ b/README.md
@@ -17,6 +17,7 @@ Options:
 - `-n`, `--dry-run`: Test run only, don't copy any data.
 - `-p`, `--progress`: Show progress, see rsync(1).
 - `-t TAG`, `--tag TAG`: Only run jobs with tag TAG (see "tags" variable below).
+- `x`, `--no-exec`: Don't run global setup-, pre-, and post-exec commands.
 
 When no *system* is given, all defined systems are backed up.
 
index a235190c3038a67f6941965e1099ee98443cfc24..70173f05e5d6b6898d1a307752c7c3e148f8af4b 100755 (executable)
@@ -16,6 +16,7 @@ PIDFILE="/var/run/$NAME.pid"
 DRYRUN=0
 VERBOSE=0
 TAG=""
+PREPOSTEXEC=1
 
 export LC_ALL=C
 
@@ -58,6 +59,7 @@ Usage() {
        echo "  -n, --dry-run       Test run only, don't copy any data."
        echo "  -p, --progress      Show progress, see rsync(1)."
        echo "  -t TAG, --tag TAG   Only run jobs with tag TAG."
+       echo "  -x, --no-exec       Don't run global pre-/post-exec commands."
        echo
        echo "When no <system> is given, all defined systems are used."
        echo
@@ -68,7 +70,7 @@ Usage() {
 }
 
 CleanUp() {
-       if [ -n "$post_exec" ]; then
+       if [[ -n "$pre_exec" && $PREPOSTEXEC -ne 0 ]]; then
                echo "Executing \"$post_exec\" ..."
                sh -c $post_exec
                if [ $? -ne 0 ]; then
@@ -305,6 +307,9 @@ while [ $# -gt 0 ]; do
                shift; TAG="$1"; shift
                [ -n "$TAG" ] || Usage
                ;;
+         "-x"|"--no-exec")
+               PREPOSTEXEC=0; shift
+               ;;
          "-"*)
                Usage
                ;;
@@ -344,7 +349,7 @@ else
        sys=("${conf_d}/"*)
 fi
 
-if [ -n "$setup_exec" ]; then
+if [[ -n "$setup_exec" && $PREPOSTEXEC -ne 0 ]]; then
        echo "Executing \"$setup_exec\" ..."
        sh -c $setup_exec
        if [ $? -ne 0 ]; then
@@ -375,7 +380,7 @@ else
        echo "$$" >>"$PIDFILE"
 fi
 
-if [ -n "$pre_exec" ]; then
+if [[ -n "$pre_exec" && $PREPOSTEXEC -ne 0 ]]; then
        echo "Executing \"$pre_exec\" ..."
        sh -c $pre_exec
        if [ $? -ne 0 ]; then