chore: updated restore.sh
36f9e0e6
1 file(s) · +22 −0
| 14 | 14 | # |
|
| 15 | 15 | # Env (same as backup.sh): R2_ENDPOINT, R2_BUCKET, AWS_ACCESS_KEY_ID, |
|
| 16 | 16 | # AWS_SECRET_ACCESS_KEY, and optional <APP>_VOLUME overrides. |
|
| 17 | + | # These are read from ./.env (or $ENV_FILE) if set; real env vars win. |
|
| 17 | 18 | # |
|
| 18 | 19 | # Run this on the HOST. It shells out to `docker run` to write into volumes; |
|
| 19 | 20 | # the backup container itself mounts those volumes read-only. |
|
| 21 | + | ||
| 22 | + | # Load .env from the script's directory (or $ENV_FILE) if present. Existing |
|
| 23 | + | # environment variables take precedence over the file. |
|
| 24 | + | SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) |
|
| 25 | + | ENV_FILE="${ENV_FILE:-$SCRIPT_DIR/.env}" |
|
| 26 | + | if [ -f "$ENV_FILE" ]; then |
|
| 27 | + | while IFS= read -r line || [ -n "$line" ]; do |
|
| 28 | + | case "$line" in |
|
| 29 | + | ''|\#*) continue ;; |
|
| 30 | + | esac |
|
| 31 | + | key="${line%%=*}" |
|
| 32 | + | case "$key" in |
|
| 33 | + | *[!A-Za-z0-9_]*|'') continue ;; |
|
| 34 | + | esac |
|
| 35 | + | # Only set if not already in the environment. |
|
| 36 | + | if [ -z "$(eval "printf '%s' \"\${$key:-}\"")" ]; then |
|
| 37 | + | val="${line#*=}" |
|
| 38 | + | export "$key=$val" |
|
| 39 | + | fi |
|
| 40 | + | done < "$ENV_FILE" |
|
| 41 | + | fi |
|
| 20 | 42 | ||
| 21 | 43 | BUCKET="${R2_BUCKET:-andromeda-backups}" |
|
| 22 | 44 |