Files
HomeBackup/scripts/synology-setup.sh
2026-02-21 16:47:41 +01:00

61 lines
2.4 KiB
Bash

#!/bin/bash
# One-time Synology setup: starts the restic REST server and creates NFS shares.
# Run this on your control node (not on the Synology directly).
# Prerequisites:
# - SSH enabled on Synology (Control Panel → Terminal & SNMP)
# - Container Manager (Docker) installed
# - admin SSH access to Synology
set -euo pipefail
SYNOLOGY_HOST="192.168.x.x" # REPLACE
SYNOLOGY_USER="admin" # REPLACE
REST_PORT=8000
REST_DATA_DIR="/volume1/backups/restic"
IMAGE_DIR="/volume1/images"
REST_SERVER_USER="restic" # REPLACE with your vault_rest_server_user
REST_SERVER_PASS="CHANGEME" # REPLACE with your vault_rest_server_password
echo "=== Synology Backup Setup ==="
echo "Target: ${SYNOLOGY_USER}@${SYNOLOGY_HOST}"
echo ""
ssh "${SYNOLOGY_USER}@${SYNOLOGY_HOST}" bash <<EOF
set -euo pipefail
# ── Create data directories ───────────────────────────────────────────────────
echo "[1/4] Creating directories..."
mkdir -p "${REST_DATA_DIR}"
mkdir -p "${IMAGE_DIR}"
chmod 755 "${IMAGE_DIR}"
# ── Create htpasswd file for REST server auth ─────────────────────────────────
echo "[2/4] Writing htpasswd..."
mkdir -p "${REST_DATA_DIR}/.htpasswd"
# Use htpasswd from busybox (available on Synology DSM)
htpasswd -bBc "${REST_DATA_DIR}/.htpasswd" "${REST_SERVER_USER}" "${REST_SERVER_PASS}"
# ── Start restic REST server container ───────────────────────────────────────
echo "[3/4] Starting REST server container..."
docker rm -f restic-rest-server 2>/dev/null || true
docker run -d \
--name restic-rest-server \
--restart always \
-p ${REST_PORT}:8000 \
-v "${REST_DATA_DIR}:/data" \
restic/rest-server:latest \
--append-only \
--htpasswd-file /data/.htpasswd \
--no-auth=false
echo "[4/4] Done."
echo ""
echo "REST server: http://${SYNOLOGY_HOST}:${REST_PORT}/"
echo "Image share: ${SYNOLOGY_HOST}:${IMAGE_DIR} (configure NFS in DSM → File Services → NFS)"
echo ""
echo "Next steps:"
echo " - In DSM: File Services → NFS → enable NFS service"
echo " - In DSM: create NFS share for ${IMAGE_DIR}, allow your Pi subnet (read/write)"
echo " - Test REST server: curl http://${REST_SERVER_USER}:${REST_SERVER_PASS}@${SYNOLOGY_HOST}:${REST_PORT}/"
EOF