Fix syntax error

This commit is contained in:
Micke Nordin 2024-06-26 09:40:36 +02:00
parent db92a5d255
commit 42831948e1

View file

@ -15,7 +15,7 @@ extra_backup_jobs["<%= client %>"]="<%= job %>"
#<% if @location.start_with?('common') %> #<% if @location.start_with?('common') %>
declare -a sixmonths=('mau') declare -a sixmonths=('mau')
if [[ " ${sixmonths[*]} " =~ " ${customer} " ]]; then if [[ " ${sixmonths[*]} " =~ " ${customer} " ]]; then
number_of_full_to_keep=6 number_of_full_to_keep=6
fi fi
declare -a projects declare -a projects
#<% @singlenodes.each do |singlenode| %> #<% @singlenodes.each do |singlenode| %>
@ -37,47 +37,45 @@ fi
function do_backup { function do_backup {
local project="${1}" local project="${1}"
local mirror="${2}" local mirror="${2}"
local bucket="${3}" local bucket="${3}"
local customer="${4}" local customer="${4}"
local mirrorbucket="${bucket}-mirror" local mirrorbucket="${bucket}-mirror"
local mountpoint="/opt/backupmounts/${bucket}" local mountpoint="/opt/backupmounts/${bucket}"
ps aux | grep duplicity | grep "[^a-zA-Z]${bucket}" > /dev/null ps aux | grep duplicity | grep "[^a-zA-Z]${bucket}" > /dev/null
local oktorun=$? # 1 == this bucket has no other bakup process in progress local oktorun=$? # 1 == this bucket has no other bakup process in progress
mkdir -p ${mountpoint} if [[ ${oktorun} -ne 0 ]]; then
if [[ ${oktorun} -ne 0 ]]; then mkdir -p ${mountpoint}
rclone mount ${project}:${bucket} ${mountpoint}/ --daemon --allow-other --dir-cache-time 24h rclone mount ${project}:${bucket} ${mountpoint}/ --daemon --allow-other --dir-cache-time 24h
rclone mkdir ${mirror}:${mirrorbucket} rclone mkdir ${mirror}:${mirrorbucket}
duplicity --full-if-older-than 1M --asynchronous-upload --tempdir /mnt --archive-dir /mnt \ duplicity --full-if-older-than 1M --asynchronous-upload --tempdir /mnt --archive-dir /mnt --no-encryption ${mountpoint} rclone://${mirror}:/${mirrorbucket}
--no-encryption ${mountpoint} rclone://${mirror}:/${mirrorbucket} if [[ "${extra_backup_jobs[${customer}]:+none}" != "none" ]] && [[ -f "${extra_backup_jobs[${customer}]}" ]]; then
if [[ -n "${extra_backup_jobs[${customer}]}" ]] && [[ -f ${extra_backup_jobs[${customer} ]]; then
${extra_backup_jobs[${customer}]} ${extra_backup_jobs[${customer}]}
fi fi
umount ${mountpoint} umount ${mountpoint}
rmdir ${mountpoint} rmdir ${mountpoint}
# Clean up # Clean up
duplicity remove-all-but-n-full ${number_of_full_to_keep} --tempdir /mnt --archive-dir /mnt \ duplicity remove-all-but-n-full ${number_of_full_to_keep} --tempdir /mnt --archive-dir /mnt --force rclone://${mirror}:/${mirrorbucket}
--force rclone://${mirror}:/${mirrorbucket}
fi fi
} }
for entry in "${projects[@]}"; do for entry in "${projects[@]}"; do
project=$(echo ${entry} | awk '{print $1}') project=$(echo ${entry} | awk '{print $1}')
mirror=$(echo ${entry} | awk '{print $2}') mirror=$(echo ${entry} | awk '{print $2}')
customer=$(echo ${entry} | awk '{print $3}') customer=$(echo ${entry} | awk '{print $3}')
for bucket in $(rclone lsd ${project}:/ | awk '{print $5}'); do for bucket in $(rclone lsd ${project}:/ | awk '{print $5}'); do
maybesize=$(timeout 30s rclone size --json ${project}:${bucket}) maybesize=$(timeout 30s rclone size --json ${project}:${bucket})
if [[ ${?} -eq 124 ]]; then if [[ ${?} -eq 124 ]]; then
size=$((${fork_limit} * 1000000001)) size=$((${fork_limit} * 1000000001))
else else
size=$(echo ${maybesize} | jq -r '.bytes' ) size=$(echo ${maybesize} | jq -r '.bytes' )
fi fi
# If bucket is above 50 GB we fork # If bucket is above 50 GB we fork
if [[ ${size} -gt $((${fork_limit} * 1000000000)) ]]; then if [[ ${size} -gt $((${fork_limit} * 1000000000)) ]]; then
do_backup ${project} ${mirror} ${bucket} ${customer} & do_backup ${project} ${mirror} ${bucket} ${customer} &
else else
do_backup ${project} ${mirror} ${bucket} ${customer} do_backup ${project} ${mirror} ${bucket} ${customer}
fi fi
done done
done done