Skip to content

Commit

Permalink
feat: Implemented option to auto refresh the UI after any backup
Browse files Browse the repository at this point in the history
- Added an env var: AUTO_REFRESH to .env.sample (defaults to false)
- Added helper script helpers/shells/cronjob.sh to call the
  borgwarehouse api for refreshing the repo status and used storage
- Added function to add this feature when creating new repositories (if
  enabled) in helpers/shells/createRepo.sh
- Added function to enable/disable this option during startup (depends
  on the configured bool for AUTO_REFRESH) in docker/docker-bw-init.sh.
	- This basically inserts or removes an additional command per
	  forced-ssh-command that calls the previous created
	  "cronjob.sh" helper script.
  • Loading branch information
mirisbowring committed Jul 21, 2024
1 parent 43e3b70 commit 50a33cb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ MAIL_SMTP_HOST=
MAIL_SMTP_PORT=
MAIL_SMTP_LOGIN=
MAIL_SMTP_PWD=
MAIL_REJECT_SELFSIGNED_TLS=
MAIL_REJECT_SELFSIGNED_TLS=

# Misc
AUTO_REFRESH=false # Set to "true" if you want to refresh the UI Metadata after any borg serve finished
14 changes: 14 additions & 0 deletions docker/docker-bw-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,26 @@ check_env() {
fi
}

check_auto_refresh() {
if [ -z "$AUTO_REFRESH" ]; then
AUTO_REFRESH="false"
export AUTO_REFRESH
fi

if [ "$AUTO_REFRESH" = "true" ]; then
sed -ri "/command=\".*${repositoryName}.*\",restrict/ {/\;\/bin\/bash \/home\/borgwarehouse\/app\/helpers\/shells\/cronjob\.sh\",restrict/! s/\",restrict/;\/bin\/bash \/home\/borgwarehouse\/app\/helpers\/shells\/cronjob\.sh\",restrict/}" "$AUTHORIZED_KEYS_FILE"
else
sed -ri "/command=\".*${repositoryName}.*\",restrict/ s/;\/bin\/bash \/home\/borgwarehouse\/app\/helpers\/shells\/cronjob.sh//g" "$AUTHORIZED_KEYS_FILE"
fi
}

check_env
init_ssh_server
check_ssh_directory
create_authorized_keys_file
check_repos_directory
get_SSH_fingerprints
check_auto_refresh

print_green "Successful initialization. BorgWarehouse is ready !"
exec supervisord -c /home/borgwarehouse/app/supervisord.conf
9 changes: 8 additions & 1 deletion helpers/shells/createRepo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ else
appendOnlyMode=""
fi

# Refresh Mode
if [ "$AUTO_REFRESH" == "true" ]; then
autoRefresh=";/bin/bash /home/borgwarehouse/app/helpers/shells/cronjob.sh"
else
autoRefresh=""
fi

## Add ssh public key in authorized_keys with borg restriction for only 1 repository and storage quota
restricted_authkeys="command=\"cd ${pool};borg serve${appendOnlyMode} --restrict-to-path ${pool}/${repositoryName} --storage-quota $2G\",restrict $1"
restricted_authkeys="command=\"cd ${pool};borg serve${appendOnlyMode} --restrict-to-path ${pool}/${repositoryName} --storage-quota $2G${autoRefresh}\",restrict $1"
echo "$restricted_authkeys" | tee -a "${authorized_keys}" >/dev/null

## Return the repositoryName
Expand Down
9 changes: 9 additions & 0 deletions helpers/shells/cronjob.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash bash

# This shell can be called to execute all cronjobs to refresh the instance
# This may be enabled as a setting to refresh the storage used after any borg serve command finishes

source /home/borgwarehouse/app/.env

curl --request POST --url "${NEXTAUTH_URL}/api/cronjob/checkStatus" --header "Authorization: Bearer ${CRONJOB_KEY}"
curl --request POST --url "${NEXTAUTH_URL}/api/cronjob/getStorageUsed" --header "Authorization: Bearer ${CRONJOB_KEY}"

0 comments on commit 50a33cb

Please sign in to comment.