Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbazhenoff committed Jan 7, 2024
1 parent d99ffae commit 1098ec4
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions backup/bareos_pool_operations/batch_process_bareos_volumes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# Batch process range of Bareos volumes script.
# Copyright (c) December, 2018. Aleksandr Bazhenov. Updated December, 2021.
# Copyright (c) 2018-2024, Aleksandr Bazhenov

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -47,18 +47,26 @@
# # batch_process_bareos_volumes.sh delete Incremental- 0032 1200


# Set up default pool path, e.g.: "/mnt/backup"
DEFAULT_POOL_PATH="/mnt/backup"
# Set up default pool name, e.g. "Full" or "Incremental"
DEFAULT_POOL_NAME="Full"


VOL_ACTION=$1
VOL_MASK=$2
VOL_START=$3
VOL_END=$4
VOL_OPT=$5
VOL_POOL=$6
VOL_PATH=$7
OPTIONS_ERROR=0


[[ -z "$VOL_MASK" ]] && echo "Error! <name_mask> is undefined." && OPTIONS_ERROR=1
[[ -z "$VOL_ACTION" ]] && echo "Error! <action> is undefined." && OPTIONS_ERROR=1
[[ -z "$VOL_START" ]] && echo "Error! <start> is undefined." && OPTIONS_ERROR=1
[[ -z "$VOL_END" ]] && echo "Error! <end> is undefined." && OPTIONS_ERROR=1
[[ -z "$VOL_POOL" ]] && VOL_POOL=$DEFAULT_POOL_PATH
[[ -z "$VOL_PATH" ]] && VOL_PATH=$DEFAULT_POOL_NAME

case $VOL_START in
''|*[!0-9]*) echo "Error! <start> is not a number." && OPTIONS_ERROR=1
Expand All @@ -73,13 +81,20 @@ if [[ -n "$VOL_OPT" ]]; then
fi
fi

if [[ $VOL_ACTION != "prune" ]] && [[ $VOL_ACTION != "purge" ]] && [[ $VOL_ACTION != "delete" ]]; then
echo "Syntax error in action option: $VOL_ACTION" && OPTIONS_ERROR=1
if [[ $VOL_ACTION != "prune" ]] && [[ $VOL_ACTION != "purge" ]] && [[ $VOL_ACTION != "delete" ]] && \
[[ $VOL_ACTION != "dumb" ]]; then
echo "Syntax error in action option: $VOL_ACTION" && OPTIONS_ERROR=1
fi

if [[ $OPTIONS_ERROR -gt 0 ]]; then
echo "Usage:"
echo "# ./batch_process_bareos_volumes.sh <action> <name_mask> <start> <end> <force|print>"
printf "Error: unrecognized option(s): %s" "$POSITIONAL"
printf "Usage:\n\n"
printf "%s %s\n" "# ./batch_process_bareos_volumes.sh <action> <name_mask> <start> <end> <force|print>" \
"<pool_name_for_dumb> <pool_path_for_dumb>"
printf "where action: prune|purge|delete|dumb.\n\n"
printf "For dumb action you can also specify pool name (e.g 'Incremental') and pool path (e.g. '/mnt/backup'):\n"
printf "%s %s\n" "# ./batch_process_bareos_volumes.sh <action> <name_mask> <start> <end> <force|print> Incremental" \
"/mnt/backup"
exit 1
fi

Expand All @@ -88,10 +103,19 @@ echo "${VOL_ACTION} from ${VOL_START} to ${VOL_END} by mask ${VOL_MASK}"
echo "Sleep 30 for sure."
sleep 30

for RANGE_ITEM in $(eval "echo {$VOL_START..$VOL_END}")
do
echo "${VOL_ACTION} volume: ${VOL_MASK}${RANGE_ITEM} $VOL_OPT"
if [[ $VOL_OPT != 'print' ]]; then
echo "${VOL_ACTION} volume=${VOL_MASK}${RANGE_ITEM} $([[ $VOL_OPT == 'force' ]] && echo 'yes')" | bconsole
fi
done
if [[ $VOL_ACTION == "dumb" ]]; then
for RANGE_ITEM in $(seq -w "$VOL_START" "$VOL_END")
do
RANGE_FILE=file_$RANGE_ITEM.txt
echo "Touch $VOL_POOL-$RANGE_FILE"
touch "$VOL_PATH$RANGE_FILE"
done
else
for RANGE_ITEM in $(eval "echo {$VOL_START..$VOL_END}")
do
echo "${VOL_ACTION} volume: ${VOL_MASK}${RANGE_ITEM} $VOL_OPT"
if [[ $VOL_OPT != 'print' ]]; then
echo "${VOL_ACTION} volume=${VOL_MASK}${RANGE_ITEM} $([[ $VOL_OPT == 'force' ]] && echo 'yes')" | bconsole
fi
done
fi

0 comments on commit 1098ec4

Please sign in to comment.