#!/usr/bin/env sh# This is very simple, yet effective backup rotation script.# Using find command, all files that are older than BACKUP_RETENTION_DAYS are accumulated and deleted using rm.
main(){BACKUP_PATH="${1:-}"FIND_EXPRESSION="${2:-mtime +7}"if[-z"${BACKUP_PATH}"];thenecho"Error: Required argument missing BACKUP_PATH"1>&2exit1fiif["$(realpath"${BACKUP_PATH}")"="/"];thenecho"Error: Dangerous BACKUP_PATH: /"1>&2exit1fiif[!-d"${BACKUP_PATH}"];thenecho"Error: BACKUP_PATH doesn't exist or is not a directory"1>&2exit1fi# shellcheck disable=SC2086find"${BACKUP_PATH}/"-typef-name"gogs-backup-*.zip"-${FIND_EXPRESSION}-print-execrm"{}"+
}
main"$@"