backup-job.sh 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env sh
  2. execute_backup_job() {
  3. BACKUP_ARG_PATH="${1:-}"
  4. BACKUP_ARG_CONFIG="${BACKUP_ARG_CONFIG:-}"
  5. BACKUP_ARG_EXCLUDE_REPOS="${BACKUP_ARG_EXCLUDE_REPOS:-}"
  6. BACKUP_EXTRA_ARGS="${BACKUP_EXTRA_ARGS:-}"
  7. cd "/app/gogs" || exit 1
  8. BACKUP_ARGS="--target=${BACKUP_ARG_PATH}"
  9. if [ -n "${BACKUP_ARG_CONFIG}" ]; then
  10. BACKUP_ARGS="${BACKUP_ARGS} --config=${BACKUP_ARG_CONFIG}"
  11. fi
  12. if [ -n "${BACKUP_ARG_EXCLUDE_REPOS}" ]; then
  13. BACKUP_ARGS="${BACKUP_ARGS} --exclude-repos=${BACKUP_ARG_EXCLUDE_REPOS}"
  14. fi
  15. if [ -n "${BACKUP_EXTRA_ARGS}" ]; then
  16. BACKUP_ARGS="${BACKUP_ARGS} ${BACKUP_EXTRA_ARGS}"
  17. fi
  18. # NOTE: We actually need word splitting to be able to pass multiple arguments.
  19. # shellcheck disable=SC2086
  20. ./gogs backup ${BACKUP_ARGS} || echo "Error: Backup job returned non-successful code." && exit 1
  21. }
  22. main() {
  23. BACKUP_PATH="${1:-}"
  24. if [ -z "${BACKUP_PATH}" ]; then
  25. echo "Required argument missing BACKUP_PATH" 1>&2
  26. exit 1
  27. fi
  28. execute_backup_job "${BACKUP_PATH}"
  29. }
  30. main "$@"