Compare commits
No commits in common. "0844c9f86a7ce60d4a242a5709458311fbc08a44" and "22645f139a0fbacb7ec2c13086bc8092c459d36d" have entirely different histories.
0844c9f86a
...
22645f139a
1 changed files with 5 additions and 15 deletions
|
|
@ -14,17 +14,12 @@ set -euo pipefail
|
||||||
|
|
||||||
cd "$(dirname "$0")/.."
|
cd "$(dirname "$0")/.."
|
||||||
|
|
||||||
# A setting from the environment, else from .env, else the fallback. Tolerates
|
|
||||||
# "export NAME=", quotes, spaces and Windows line endings.
|
|
||||||
setting() { # name, fallback
|
setting() { # name, fallback
|
||||||
local from_env="${!1:-}"
|
local from_env="${!1:-}"
|
||||||
if [ -n "$from_env" ]; then echo "$from_env"; return; fi
|
if [ -n "$from_env" ]; then echo "$from_env"; return; fi
|
||||||
if [ -f .env ]; then
|
if [ -f .env ]; then
|
||||||
local line
|
local line
|
||||||
line="$(sed -e 's/\r$//' .env \
|
line="$(grep -E "^$1=" .env | tail -1 | cut -d= -f2-)"
|
||||||
| grep -E "^[[:space:]]*(export[[:space:]]+)?$1[[:space:]]*=" \
|
|
||||||
| tail -1 | cut -d= -f2- \
|
|
||||||
| sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/^"\(.*\)"$/\1/' -e "s/^'\(.*\)'$/\1/")"
|
|
||||||
if [ -n "$line" ]; then echo "$line"; return; fi
|
if [ -n "$line" ]; then echo "$line"; return; fi
|
||||||
fi
|
fi
|
||||||
echo "$2"
|
echo "$2"
|
||||||
|
|
@ -35,15 +30,6 @@ DATA_DIR="$(setting DATA_DIR ./data)"
|
||||||
KEEP_DAYS="$(setting KEEP_DAYS 14)"
|
KEEP_DAYS="$(setting KEEP_DAYS 14)"
|
||||||
stamp="$(date +%Y-%m-%d)"
|
stamp="$(date +%Y-%m-%d)"
|
||||||
|
|
||||||
echo "$(date '+%F %T') data: $DATA_DIR → backups: $BACKUP_DIR"
|
|
||||||
|
|
||||||
# Checked before anything is written: on an external disk that isn't mounted,
|
|
||||||
# the folder is simply missing, and a backup of nothing is worse than none.
|
|
||||||
if [ ! -d "$DATA_DIR/uploads" ]; then
|
|
||||||
echo "$(date '+%F %T') FAILED: no $DATA_DIR/uploads — is the disk mounted, and is DATA_DIR set in .env?" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p "$BACKUP_DIR/db"
|
mkdir -p "$BACKUP_DIR/db"
|
||||||
|
|
||||||
# --- the database -----------------------------------------------------------
|
# --- the database -----------------------------------------------------------
|
||||||
|
|
@ -76,5 +62,9 @@ find "$BACKUP_DIR/db" -name 'printhive-*.dump' -type f -mtime "+$KEEP_DAYS" -del
|
||||||
# --- the model files --------------------------------------------------------
|
# --- the model files --------------------------------------------------------
|
||||||
# A mirror, not a history: it matches what's there now, deletions included.
|
# A mirror, not a history: it matches what's there now, deletions included.
|
||||||
# Thumbnails, previews and extracted archives are left out — they rebuild.
|
# Thumbnails, previews and extracted archives are left out — they rebuild.
|
||||||
|
if [ ! -d "$DATA_DIR/uploads" ]; then
|
||||||
|
echo "$(date '+%F %T') FAILED: no $DATA_DIR/uploads — is the disk mounted?" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
rsync -a --delete "$DATA_DIR/uploads/" "$BACKUP_DIR/uploads/"
|
rsync -a --delete "$DATA_DIR/uploads/" "$BACKUP_DIR/uploads/"
|
||||||
echo "$(date '+%F %T') files → $BACKUP_DIR/uploads ($(du -sh "$BACKUP_DIR/uploads" | cut -f1))"
|
echo "$(date '+%F %T') files → $BACKUP_DIR/uploads ($(du -sh "$BACKUP_DIR/uploads" | cut -f1))"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue