Compare commits

...

3 commits

Author SHA1 Message Date
Micke Nordin adeaea5a37 Fix bug in script 2024-06-26 10:04:41 +02:00
Micke Nordin 4a45670bec Fix syntax error 2024-06-26 10:04:41 +02:00
Micke Nordin 3738e703b6 Clean up logic 2024-06-26 10:04:41 +02:00
3 changed files with 58 additions and 56 deletions

View file

@ -45,17 +45,19 @@ function do_backup {
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
if [[ ${oktorun} -ne 0 ]]; then
mkdir -p ${mountpoint} mkdir -p ${mountpoint}
[[ ${oktorun} -ne 0 ]] && 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}
[[ ${oktorun} -ne 0 ]] && 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
[[ -n "${extra_backup_jobs[${customer}]}" ]] && [[ -f ${extra_backup_jobs[${customer} ]] && ${extra_backup_jobs[${customer}]} ${extra_backup_jobs[${customer}]}
fi
umount ${mountpoint} umount ${mountpoint}
rmdir ${mountpoint} rmdir ${mountpoint}
# Clean up # Clean up
[ ${oktorun} -ne 0 ] && 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
} }
for entry in "${projects[@]}"; do for entry in "${projects[@]}"; do

View file

@ -25,7 +25,7 @@ dirty=0
primary='' primary=''
declare -a users=( 'admin' ) declare -a users=( 'admin' )
cd "${tempdir}" || echo "Could not cd to tempdir" cd "${tempdir}" || echo "Could not cd to tempdir"
declare -a projects=( "${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.assigned | "\(.[].project)"' /etc/hiera/data/common.yaml ) declare -a projects=( $("${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.assigned | "\(.[].project)"' /etc/hiera/data/common.yaml) )
if [[ "${include_userbuckets}" == "true" ]]; then if [[ "${include_userbuckets}" == "true" ]]; then
primary=$("${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.primary_project' /etc/hiera/data/common.yaml) primary=$("${yq}" -r '.project_mapping.'"${customer}"'.'"${environment}"'.primary_project' /etc/hiera/data/common.yaml)
projects+=( "${primary}" ) projects+=( "${primary}" )