script tidyups
This commit is contained in:
Executable → Regular
+14
-5
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# AUTHOR: Karl Mowatt-Wilson (updates by zorruno)
|
||||
# ORIGINAL AUTHOR: kmw (updates by zorruno)
|
||||
# HISTORY:
|
||||
# 2026-04-20 - add configurable SOURCE_BASE_DIR and -s option for source path fallback.
|
||||
# 2025-08-22 - add start wait with one retry; fix find_working_dir typo; tidy.
|
||||
# 2025-08-22 - tidy, stricter bash, compose detection, better checks, clearer logging.
|
||||
# 2022-03-25 - add -t option for dry-run (no backups performed).
|
||||
@@ -27,6 +28,9 @@ dryrun=
|
||||
# base directory for backups
|
||||
BACKUP_DIR="/dockerbackups"
|
||||
|
||||
# base directory for source docker project folders
|
||||
SOURCE_BASE_DIR="${SOURCE_BASE_DIR:-/dockervolumes}"
|
||||
|
||||
# start/health wait tuning
|
||||
START_TIMEOUT=90 # seconds to wait for service to be up
|
||||
WAIT_INTERVAL=3 # seconds between polls
|
||||
@@ -99,23 +103,27 @@ tidy_up() {
|
||||
|
||||
usage() {
|
||||
cat 1>&2 <<EOF
|
||||
Usage: ${0##*/} [-f containers_list_file] [-t] [-v] [-h]
|
||||
Usage: ${0##*/} [-f containers_list_file] [-s source_base_dir] [-t] [-v] [-h]
|
||||
|
||||
-t Test (dry run; no backups performed)
|
||||
-v Verbose (debug logging to stderr)
|
||||
-f FILE File containing list of container names
|
||||
Default: '$containersfile'
|
||||
-s DIR Base directory containing container/project folders
|
||||
Default: '$SOURCE_BASE_DIR'
|
||||
-h Show this help
|
||||
|
||||
Example:
|
||||
${0##*/} -f containers.servername.txt
|
||||
${0##*/} -f containers.servername.txt -s /dockervolumes
|
||||
EOF
|
||||
}
|
||||
|
||||
parse_cmdline() {
|
||||
while getopts ":f:htv" opt; do
|
||||
while getopts ":f:hs:tv" opt; do
|
||||
case "$opt" in
|
||||
f) containersfile="$OPTARG" ;;
|
||||
s) SOURCE_BASE_DIR="$OPTARG" ;;
|
||||
h) usage; exit 0 ;;
|
||||
t) dryrun=1 ;;
|
||||
v) dbg=VERBOSE ;;
|
||||
@@ -267,8 +275,8 @@ find_working_dir() {
|
||||
wd="$(docker inspect "$name" 2>/dev/null | jq -r '.[0].Config.Labels["com.docker.compose.project.working_dir"] // empty')"
|
||||
fi
|
||||
if [ -z "$wd" ]; then
|
||||
if [ -d "/dockervolumes/$name" ]; then
|
||||
wd="/dockervolumes/$name"
|
||||
if [ -d "$SOURCE_BASE_DIR/$name" ]; then
|
||||
wd="$SOURCE_BASE_DIR/$name"
|
||||
elif [ -d "$HOME/prj/docker/$name" ]; then
|
||||
wd="$HOME/prj/docker/$name"
|
||||
else
|
||||
@@ -335,6 +343,7 @@ parse_cmdline "$@"
|
||||
|
||||
debug "-----"
|
||||
debug "logfile = '$logfile'"
|
||||
debug "source_base_dir = '$SOURCE_BASE_DIR'"
|
||||
|
||||
toolcheck docker jq sed tar
|
||||
|
||||
|
||||
Reference in New Issue
Block a user