Swap deprecated --last option with --latest 1
This commit is contained in:
@@ -22,7 +22,7 @@ COMPRESSION="auto"
|
|||||||
|
|
||||||
# Function to display usage
|
# Function to display usage
|
||||||
usage() {
|
usage() {
|
||||||
cat << EOF
|
cat <<EOF
|
||||||
Usage: $0 [OPTIONS] <source_path> <repository>
|
Usage: $0 [OPTIONS] <source_path> <repository>
|
||||||
|
|
||||||
Generic backup script using Restic for any folder and repository.
|
Generic backup script using Restic for any folder and repository.
|
||||||
@@ -90,7 +90,7 @@ log_message() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$LOG_FILE" ]; then
|
if [ -n "$LOG_FILE" ]; then
|
||||||
echo "$message" >> "$LOG_FILE"
|
echo "$message" >>"$LOG_FILE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,15 +105,15 @@ send_healthcheck() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
case "$status" in
|
case "$status" in
|
||||||
"START")
|
"START")
|
||||||
curl -fsS -m 10 --retry 3 "$HEALTHCHECK_URL/start" >/dev/null 2>&1 || true
|
curl -fsS -m 10 --retry 3 "$HEALTHCHECK_URL/start" >/dev/null 2>&1 || true
|
||||||
;;
|
;;
|
||||||
"SUCCESS")
|
"SUCCESS")
|
||||||
curl -fsS -m 10 --retry 3 --data-raw "$message" "$HEALTHCHECK_URL" >/dev/null 2>&1 || true
|
curl -fsS -m 10 --retry 3 --data-raw "$message" "$HEALTHCHECK_URL" >/dev/null 2>&1 || true
|
||||||
;;
|
;;
|
||||||
"FAILED"|"WARNING")
|
"FAILED" | "WARNING")
|
||||||
curl -fsS -m 10 --retry 3 --data-raw "$message" "$HEALTHCHECK_URL/fail" >/dev/null 2>&1 || true
|
curl -fsS -m 10 --retry 3 --data-raw "$message" "$HEALTHCHECK_URL/fail" >/dev/null 2>&1 || true
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[ "$VERBOSE" = true ] && echo "Healthcheck sent: $status - $message"
|
[ "$VERBOSE" = true ] && echo "Healthcheck sent: $status - $message"
|
||||||
@@ -126,87 +126,87 @@ POSITIONAL_ARGS=()
|
|||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-p|--password-file)
|
-p | --password-file)
|
||||||
RESTIC_PASSWORD_FILE="$2"
|
RESTIC_PASSWORD_FILE="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-l|--log-file)
|
-l | --log-file)
|
||||||
LOG_FILE="$2"
|
LOG_FILE="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-h|--healthcheck)
|
-h | --healthcheck)
|
||||||
HEALTHCHECK_URL="$2"
|
HEALTHCHECK_URL="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-t|--tag)
|
-t | --tag)
|
||||||
CUSTOM_TAGS+=("$2")
|
CUSTOM_TAGS+=("$2")
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--tag-prefix)
|
--tag-prefix)
|
||||||
TAG_PREFIX="$2"
|
TAG_PREFIX="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--keep-daily)
|
--keep-daily)
|
||||||
KEEP_DAILY="$2"
|
KEEP_DAILY="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--keep-weekly)
|
--keep-weekly)
|
||||||
KEEP_WEEKLY="$2"
|
KEEP_WEEKLY="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--keep-monthly)
|
--keep-monthly)
|
||||||
KEEP_MONTHLY="$2"
|
KEEP_MONTHLY="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--keep-yearly)
|
--keep-yearly)
|
||||||
KEEP_YEARLY="$2"
|
KEEP_YEARLY="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-e|--exclude)
|
-e | --exclude)
|
||||||
EXCLUDE_PATTERNS+=("$2")
|
EXCLUDE_PATTERNS+=("$2")
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--no-exclude-caches)
|
--no-exclude-caches)
|
||||||
EXCLUDE_CACHES=false
|
EXCLUDE_CACHES=false
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--no-one-file-system)
|
--no-one-file-system)
|
||||||
ONE_FILE_SYSTEM=false
|
ONE_FILE_SYSTEM=false
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--compression)
|
--compression)
|
||||||
case "$2" in
|
case "$2" in
|
||||||
auto|max|off|fastest|better)
|
auto | max | off | fastest | better)
|
||||||
COMPRESSION="$2"
|
COMPRESSION="$2"
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Error: Invalid compression value '$2'. Valid values: auto, max, off, fastest, better"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--dry-run)
|
|
||||||
DRY_RUN=true
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-v|--verbose)
|
|
||||||
VERBOSE=true
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--help)
|
|
||||||
usage
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
-*)
|
|
||||||
echo "Unknown option $1"
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
POSITIONAL_ARGS+=("$1")
|
echo "Error: Invalid compression value '$2'. Valid values: auto, max, off, fastest, better"
|
||||||
shift
|
exit 1
|
||||||
;;
|
;;
|
||||||
|
esac
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--dry-run)
|
||||||
|
DRY_RUN=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-v | --verbose)
|
||||||
|
VERBOSE=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
echo "Unknown option $1"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
POSITIONAL_ARGS+=("$1")
|
||||||
|
shift
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -294,7 +294,7 @@ send_healthcheck "START" "Starting backup of $BACKUP_NAME"
|
|||||||
# Pre-backup: Check repository connectivity
|
# Pre-backup: Check repository connectivity
|
||||||
log_message "Checking repository connectivity..."
|
log_message "Checking repository connectivity..."
|
||||||
CONNECTIVITY_OUTPUT=""
|
CONNECTIVITY_OUTPUT=""
|
||||||
if ! CONNECTIVITY_OUTPUT=$(eval "$RESTIC_CMD snapshots --last" 2>&1); then
|
if ! CONNECTIVITY_OUTPUT=$(eval "$RESTIC_CMD snapshots --latest 1" 2>&1); then
|
||||||
log_message "WARNING: Could not connect to repository or no snapshots exist yet"
|
log_message "WARNING: Could not connect to repository or no snapshots exist yet"
|
||||||
if [ "$VERBOSE" = true ]; then
|
if [ "$VERBOSE" = true ]; then
|
||||||
log_message "Connectivity check output: $CONNECTIVITY_OUTPUT"
|
log_message "Connectivity check output: $CONNECTIVITY_OUTPUT"
|
||||||
|
|||||||
Reference in New Issue
Block a user