deploy: Odroid XU4 이전 서버 설정과 운영 문서 추가
ysscboxx.duckdns.org 서버의 실제 설정을 서버 경로 구조 그대로 보관합니다. - nginx 사이트 설정 (yonggong + Pole Mapper) 과 www-data 실행/LogsDirectory 드롭인 - polemapper.service, 하드웨어 워치독, smartd, fstab (SSD 루트 + SD /boot bind) - Nextcloud 외부 백업 스크립트/타이머 (비밀번호 7z, 14개 보관) 와 설정 예시 - README: SSD 루트 구성과 SD 되돌리기, 상태 감시, 백업/복원, 적용 방법 - docs/deployment.md 에서 이전 서버 문서로 연결 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
215bdb6fca
commit
d4795fbbec
@@ -0,0 +1,101 @@
|
||||
# Odroid XU4 이전 서버 (`ysscboxx.duckdns.org`)
|
||||
|
||||
OCI VM에서 옮겨 올 자체 서버입니다. 현재 `ysscboxx.duckdns.org`로 서비스 중이며,
|
||||
`saftyovhcable.kr` 블록도 미리 들어 있어 **DNS(IP)만 바꾸면 이 서버로 넘어옵니다.**
|
||||
|
||||
이 폴더는 서버의 실제 설정 파일을 **같은 경로 구조로** 보관합니다
|
||||
(예: `etc/nginx/sites-available/yonggong` → 서버의 `/etc/nginx/sites-available/yonggong`).
|
||||
서버 설정을 바꾸면 이 폴더도 함께 갱신하세요.
|
||||
|
||||
## 구성 (2026-11-29 기준)
|
||||
|
||||
| 항목 | 값 |
|
||||
| --- | --- |
|
||||
| 보드 | Odroid XU4 (armv7l 32비트, RAM 2GB) |
|
||||
| OS | Armbian 26.11 (Debian trixie), 커널 6.6 `current` |
|
||||
| 접속 | `ssh -p 2212 gerd@ysscboxx.duckdns.org` (키 인증) |
|
||||
| 루트(`/`) | **USB3 SSD** (Samsung 32GB mSATA, RTL9201 브리지, UAS) |
|
||||
| SD 카드 | 부트 전용. `/media/sdboot`에 마운트, `/boot`는 그 안의 `boot/`를 bind 마운트 |
|
||||
| Node.js | v20 (Debian 패키지, `/usr/bin/node`) — `node:sqlite` 없음, 네이티브 모듈은 보드에서 빌드됨 |
|
||||
| 웹서버 | nginx (www-data로 실행, `etc/systemd/system/nginx.service.d/`) |
|
||||
| 앱 | `yonggong.service` (:3000, 저장소 `deploy/yonggong.service`), `polemapper.service` (:4000) |
|
||||
| 로그 | `/var/log`는 RAM 디스크(armbian-ramlog), 스왑은 zram |
|
||||
|
||||
### 서비스와 데이터 위치
|
||||
|
||||
| 서비스 | 주소 | 데이터 |
|
||||
| --- | --- | --- |
|
||||
| yonggong (이 저장소) | `/` | `/srv/yonggong/data/prod.db`, `/srv/yonggong/storage/uploads` |
|
||||
| Pole Mapper | `/polemapper/` | `/srv/polemapper/server/data/polemapper.db` (SQLite), `/srv/polemapper/server/uploads` |
|
||||
|
||||
Pole Mapper는 별도 저장소(`Pole-Mapper`)입니다. 2026-11-29에 DB를 Supabase에서 SQLite로 옮겼습니다.
|
||||
|
||||
## SSD 루트 구성과 되돌리기
|
||||
|
||||
- `/boot/boot.ini`의 `setenv rootdev "UUID=<SSD UUID>"`가 SSD를 루트로 지정합니다.
|
||||
- `etc/fstab` 참고: SSD를 `/`(noatime), SD를 `/media/sdboot`(nofail), `/boot`는 bind.
|
||||
커널 업데이트 시 파일이 SD의 `/boot`에 기록되어야 부팅이 되므로 bind 마운트가 필수입니다.
|
||||
- USB 저장장치 드라이버(uas, usb-storage, sd_mod)는 initramfs에 들어 있습니다(`MODULES=most`).
|
||||
|
||||
**SSD 고장 시 SD로 되돌리기:** SD 카드를 PC에 꽂고 `boot/boot.ini`를
|
||||
`boot/boot.ini.bak-sdroot-20261129`로 덮어쓰거나 `rootdev`를 SD의 UUID로 되돌립니다.
|
||||
SD의 시스템은 2026-11-29 01시 상태이므로, 이후 데이터는 아래 외부 백업에서 복원합니다.
|
||||
|
||||
## 상태 감시
|
||||
|
||||
- `etc/smartd.conf`: SSD SMART 감시 (매일 03시 짧은 검사, 일요일 04시 긴 검사, 50/60℃ 경고)
|
||||
- 즉시 확인: `sudo smartctl -a -d sat /dev/sda`
|
||||
- `fstrim.timer`: 주 1회 TRIM
|
||||
- `etc/systemd/system.conf.d/watchdog.conf`: 하드웨어 워치독 15초 (멈추면 자동 재부팅)
|
||||
|
||||
## 백업
|
||||
|
||||
| 종류 | 시각 | 내용 | 위치 |
|
||||
| --- | --- | --- | --- |
|
||||
| 로컬 (`deploy/backup.sh` → `/usr/local/sbin/yonggong-backup.sh`) | 매일 03:30 | yonggong DB + 첨부 | `/srv/yonggong/backups` (14일) |
|
||||
| **외부** (`usr/local/sbin/offsite-backup.sh`) | 매일 04:30 (`offsite-backup.timer`) | 아래 참고 | Nextcloud 공유 폴더, 최근 14개 |
|
||||
|
||||
외부 백업 내용: `/etc`, `/srv`(node_modules·캐시 제외), `/usr/local`, crontab, 홈 디렉터리,
|
||||
설치 패키지 목록, 모든 SQLite DB의 `.backup` 스냅샷(`meta/sqlite-snapshots/`),
|
||||
Supabase 테이블 JSON(`meta/supabase/`, 이전 전 데이터 — 정리 예정).
|
||||
`tar.gz`를 비밀번호 7z(AES-256, 파일명 암호화)로 감싸 업로드합니다.
|
||||
|
||||
설정은 서버의 `/etc/offsite-backup.conf`(600)에 있습니다. 형식은 `etc/offsite-backup.conf.example` 참고.
|
||||
|
||||
```bash
|
||||
sudo systemctl start offsite-backup.service # 즉시 백업
|
||||
sudo journalctl -u offsite-backup.service -n 20 # 결과 확인
|
||||
systemctl list-timers offsite-backup.timer # 다음 실행 시각
|
||||
```
|
||||
|
||||
### 복원
|
||||
|
||||
```bash
|
||||
7z x odroidxu4-YYYYMMDD-HHMM.7z # 비밀번호 입력 → backup.tar.gz
|
||||
mkdir restore && sudo tar -xzpf backup.tar.gz -C restore
|
||||
# 필요한 것만 복사. DB는 restore/var/tmp/offsite.*/meta/sqlite-snapshots/ 의 스냅샷을 쓰는 것이 안전
|
||||
# node_modules 는 백업에 없으므로 앱 디렉터리에서 npm ci --omit=dev 로 다시 설치
|
||||
```
|
||||
|
||||
## 이 폴더의 파일을 서버에 적용하기
|
||||
|
||||
```bash
|
||||
# 예: nginx 설정
|
||||
sudo install -m 644 etc/nginx/sites-available/yonggong /etc/nginx/sites-available/yonggong
|
||||
sudo nginx -t && sudo systemctl reload nginx
|
||||
|
||||
# 예: systemd 유닛 / 드롭인
|
||||
sudo install -m 644 etc/systemd/system/offsite-backup.{service,timer} /etc/systemd/system/
|
||||
sudo systemctl daemon-reload && sudo systemctl enable --now offsite-backup.timer
|
||||
|
||||
# 백업 스크립트 (7zip, sqlite3, jq, curl 필요)
|
||||
sudo apt-get install -y 7zip sqlite3 jq curl smartmontools
|
||||
sudo install -m 750 usr/local/sbin/offsite-backup.sh usr/local/sbin/supabase-export.sh /usr/local/sbin/
|
||||
```
|
||||
|
||||
## 주의
|
||||
|
||||
- nginx는 www-data로 실행되고 `/var/log`가 부팅마다 RAM에 새로 만들어지므로,
|
||||
`20-logsdir.conf`(`LogsDirectory=nginx`)가 없으면 재부팅 후 nginx가 로그 권한 오류로 시작하지 못합니다.
|
||||
- 보드에서 `npm install`할 때 better-sqlite3 같은 네이티브 모듈은 소스 빌드되어 몇 분 걸립니다
|
||||
(build-essential 필요). 앱 디렉터리 소유자로 실행하세요 (예: `sudo -u polemapper -H npm install --omit=dev`).
|
||||
@@ -0,0 +1,6 @@
|
||||
# root on USB SSD (migrated 2026-11-29). Original SD fstab: /etc/fstab.bak-20261129
|
||||
UUID=cee02eab-716a-459e-b972-67f70e273931 / ext4 defaults,noatime,commit=120,errors=remount-ro 0 1
|
||||
# SD card: holds boot files only; /boot is bind-mounted from it so kernel updates land on the SD
|
||||
UUID=1060695b-0075-48b0-bcc8-848cdfb0b889 /media/sdboot ext4 defaults,noatime,nofail 0 2
|
||||
/media/sdboot/boot /boot none bind,nofail,x-systemd.requires-mounts-for=/media/sdboot 0 0
|
||||
tmpfs /tmp tmpfs defaults,nosuid 0 0
|
||||
@@ -0,0 +1,189 @@
|
||||
# 용산 공중케이블 협의회 사이트 (이전 서버)
|
||||
# /etc/nginx/sites-available/yonggong
|
||||
|
||||
# yonggong_app upstream은 /etc/nginx/conf.d/yonggong-upstream.conf에 정의됨
|
||||
|
||||
upstream polemapper_api {
|
||||
server 127.0.0.1:4000;
|
||||
keepalive 16;
|
||||
}
|
||||
|
||||
# --- 테스트 도메인 HTTP: ACME만 허용하고 나머지는 HTTPS로 ---
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name ysscboxx.duckdns.org;
|
||||
|
||||
root /var/www/html;
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /var/www/html;
|
||||
}
|
||||
|
||||
location / {
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
# --- 기존 도메인 HTTP -> HTTPS (나중에 IP만 이 서버로 변경하면 됨) ---
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name saftyovhcable.kr xn--ob0bs83a9mfulcsua52c2xubym.xn--3e0b707e;
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /var/www/html;
|
||||
}
|
||||
|
||||
location / {
|
||||
return 301 https://saftyovhcable.kr$request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
# --- 테스트 도메인 HTTPS: 용공협 + Pole Mapper ---
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
http2 on;
|
||||
server_name ysscboxx.duckdns.org;
|
||||
|
||||
root /var/www/html;
|
||||
index index.html;
|
||||
|
||||
ssl_certificate /etc/letsencrypt/live/ysscboxx.duckdns.org/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/ysscboxx.duckdns.org/privkey.pem;
|
||||
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||
|
||||
client_max_body_size 60m;
|
||||
client_body_timeout 120s;
|
||||
add_header Strict-Transport-Security "max-age=31536000" always;
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ { root /var/www/html; }
|
||||
|
||||
# 레거시 정적 자산
|
||||
location = /addMarker.html { try_files $uri =404; }
|
||||
location = /blogload.js { try_files $uri =404; }
|
||||
location = /styles.css { try_files $uri =404; }
|
||||
location ^~ /res/ { try_files $uri =404; expires 7d; access_log off; }
|
||||
|
||||
# Pole Mapper (Vite 정적 빌드)
|
||||
location = /polemapper { return 301 /polemapper/; }
|
||||
|
||||
location ^~ /polemapper/assets/ {
|
||||
root /var/www/html;
|
||||
expires 1y;
|
||||
access_log off;
|
||||
add_header Cache-Control "public, immutable";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location ^~ /polemapper/api/ {
|
||||
proxy_pass http://polemapper_api/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_read_timeout 120s;
|
||||
proxy_send_timeout 120s;
|
||||
}
|
||||
|
||||
location ^~ /polemapper/uploads/ {
|
||||
proxy_pass http://polemapper_api/uploads/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
expires 1y;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location ^~ /polemapper/ {
|
||||
root /var/www/html;
|
||||
try_files $uri $uri/ /polemapper/index.html;
|
||||
}
|
||||
|
||||
# 기존 Next.js 앱
|
||||
location /_next/static/ {
|
||||
proxy_pass http://yonggong_app;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
access_log off;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://yonggong_app;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "";
|
||||
proxy_read_timeout 120s;
|
||||
proxy_send_timeout 120s;
|
||||
}
|
||||
}
|
||||
|
||||
# --- 기존 도메인 HTTPS (기존 인증서 그대로 사용) ---
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
http2 on;
|
||||
server_name saftyovhcable.kr xn--ob0bs83a9mfulcsua52c2xubym.xn--3e0b707e;
|
||||
|
||||
root /var/www/html;
|
||||
index index.html;
|
||||
|
||||
ssl_certificate /etc/letsencrypt/live/saftyovhcable.kr/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/saftyovhcable.kr/privkey.pem;
|
||||
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||
|
||||
client_max_body_size 60m;
|
||||
client_body_timeout 120s;
|
||||
add_header Strict-Transport-Security "max-age=31536000" always;
|
||||
|
||||
# 레거시 정적 자산
|
||||
location = /addMarker.html { try_files $uri =404; }
|
||||
location ^~ /res/ { try_files $uri =404; expires 7d; access_log off; }
|
||||
location = /blogload.js { try_files $uri =404; }
|
||||
location ^~ /.well-known/acme-challenge/ { root /var/www/html; }
|
||||
|
||||
location = /index.html { return 301 /; }
|
||||
location = /index.htm { return 301 /; }
|
||||
location = /news { return 301 /news/notice; }
|
||||
location = /board { return 301 /news/notice; }
|
||||
|
||||
location /_next/static/ {
|
||||
proxy_pass http://yonggong_app;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
access_log off;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://yonggong_app;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "";
|
||||
proxy_read_timeout 120s;
|
||||
proxy_send_timeout 120s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
# /etc/offsite-backup.conf (chmod 600, root 소유)
|
||||
# 실제 값은 저장소에 넣지 않습니다. 서버의 /etc/offsite-backup.conf 를 참고하세요.
|
||||
|
||||
# Nextcloud 공개 공유 폴더의 WebDAV 주소와 공유 토큰 (공유 링크 .../s/<토큰>)
|
||||
DAV_URL="https://cloud.example.com/public.php/webdav"
|
||||
SHARE_TOKEN="<share-token>"
|
||||
# 공유 링크에 비밀번호를 걸었다면 여기에 입력
|
||||
SHARE_PASS=""
|
||||
# 업로드하는 .7z 압축 파일의 비밀번호
|
||||
ARCHIVE_PASS='<archive-password>'
|
||||
# 공유 폴더에 남길 최근 백업 개수
|
||||
KEEP=14
|
||||
@@ -0,0 +1 @@
|
||||
/dev/sda -d sat -a -o on -S on -s (S/../.././03|L/../../7/04) -W 4,50,60
|
||||
@@ -0,0 +1,3 @@
|
||||
[Manager]
|
||||
RuntimeWatchdogSec=15
|
||||
RebootWatchdogSec=2min
|
||||
@@ -0,0 +1,18 @@
|
||||
[Service]
|
||||
User=www-data
|
||||
Group=www-data
|
||||
SupplementaryGroups=
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
||||
SecureBits=keep-caps
|
||||
RuntimeDirectory=nginx
|
||||
RuntimeDirectoryMode=0755
|
||||
PIDFile=/run/nginx/nginx.pid
|
||||
ExecStartPre=
|
||||
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
|
||||
ExecStart=
|
||||
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
|
||||
ExecReload=
|
||||
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
|
||||
ExecStop=
|
||||
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx/nginx.pid
|
||||
@@ -0,0 +1,4 @@
|
||||
[Service]
|
||||
# /var/log is a RAM disk (armbian-ramlog); let systemd create/own the log dir for www-data on every start
|
||||
LogsDirectory=nginx
|
||||
LogsDirectoryMode=0750
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Offsite backup to Nextcloud (password-protected 7z)
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/sbin/offsite-backup.sh
|
||||
Nice=10
|
||||
IOSchedulingClass=idle
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Daily offsite backup (after 03:30 local app backup)
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 04:30
|
||||
RandomizedDelaySec=15min
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=Pole Mapper API
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=polemapper
|
||||
Group=polemapper
|
||||
WorkingDirectory=/srv/polemapper
|
||||
EnvironmentFile=/srv/polemapper/.env
|
||||
ExecStart=/usr/bin/node server/index.js
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
# Daily offsite backup of odroid system/app data to Nextcloud as a password-protected 7z.
|
||||
# Restore: 7z x FILE.7z (asks for the archive password)
|
||||
# sudo tar -xzpf backup.tar.gz -C /restore/target
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
source /etc/offsite-backup.conf
|
||||
HOST=$(hostname); TS=$(date +%Y%m%d-%H%M)
|
||||
NAME="$HOST-$TS.7z"
|
||||
WORK=$(mktemp -d /var/tmp/offsite.XXXXXX)
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
AUTH=(-u "$SHARE_TOKEN:$SHARE_PASS")
|
||||
|
||||
# metadata + consistent SQLite snapshots (live DB files may be mid-write)
|
||||
mkdir -p "$WORK/meta"
|
||||
dpkg --get-selections > "$WORK/meta/dpkg-selections.txt"
|
||||
lsblk -o NAME,SIZE,FSTYPE,UUID,MOUNTPOINT > "$WORK/meta/lsblk.txt"
|
||||
find /srv -name node_modules -prune -o \( -name "*.db" -o -name "*.sqlite" -o -name "*.sqlite3" \) -type f -print \
|
||||
| grep -v /backups/ | while read -r db; do
|
||||
out="$WORK/meta/sqlite-snapshots$db"; mkdir -p "$(dirname "$out")"
|
||||
sqlite3 "$db" ".backup '$out'"
|
||||
done
|
||||
|
||||
# Supabase (polemapper DB lives there, not on this box)
|
||||
/usr/local/sbin/supabase-export.sh "$WORK/meta/supabase" || echo "WARNING: supabase export failed"
|
||||
|
||||
# tar keeps Linux owners/permissions; 7z adds the password (AES-256, file names hidden too)
|
||||
tar -C / -czpf "$WORK/backup.tar.gz" --warning=no-file-changed --ignore-failed-read \
|
||||
--exclude='*/node_modules' --exclude='*/.next/cache' --exclude='home/*/.cache' --exclude='home/*/.nvm' --exclude='home/*/.npm' --exclude='root/.npm' --exclude='root/.cache' \
|
||||
etc srv usr/local var/spool/cron home root "${WORK#/}/meta" || [ $? -eq 1 ]
|
||||
7z a -t7z -mx=0 -mhe=on -p"$ARCHIVE_PASS" "$WORK/$NAME" "$WORK/backup.tar.gz" >/dev/null
|
||||
SIZE=$(du -h "$WORK/$NAME" | cut -f1)
|
||||
|
||||
curl -sS --fail --retry 3 --retry-delay 30 "${AUTH[@]}" -T "$WORK/$NAME" "$DAV_URL/$NAME"
|
||||
echo "uploaded $NAME ($SIZE)"
|
||||
|
||||
# retention: keep newest $KEEP archives of this host
|
||||
mapfile -t files < <(curl -sS --fail "${AUTH[@]}" -X PROPFIND -H "Depth: 1" "$DAV_URL/" \
|
||||
| grep -o "<d:href>[^<]*</d:href>" | sed -E "s|</?d:href>||g; s|.*/||" \
|
||||
| grep -E "^$HOST-[0-9]{8}-[0-9]{4}\.7z$" | sort)
|
||||
n=${#files[@]}
|
||||
if (( n > KEEP )); then
|
||||
for f in "${files[@]:0:n-KEEP}"; do
|
||||
curl -sS --fail "${AUTH[@]}" -X DELETE "$DAV_URL/$f" && echo "pruned $f"
|
||||
done
|
||||
fi
|
||||
echo "done: $(( n > KEEP ? KEEP : n )) backups on share"
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
# Export all Supabase (PostgREST) tables of polemapper as JSON + schema.
|
||||
# Usage: supabase-export.sh OUTDIR (reads SUPABASE_URL / SUPABASE_SERVICE_ROLE_KEY from /srv/polemapper/.env)
|
||||
set -euo pipefail
|
||||
OUT=${1:?outdir}; ENV=/srv/polemapper/.env; PAGE=1000
|
||||
getenv() { grep -E "^$1=" "$ENV" | tail -1 | cut -d= -f2- | tr -d "\"'"; }
|
||||
U=$(getenv SUPABASE_URL); K=$(getenv SUPABASE_SERVICE_ROLE_KEY)
|
||||
[ -n "$U" ] && [ -n "$K" ] || { echo "supabase: credentials not found in $ENV"; exit 1; }
|
||||
H=(-H "apikey: $K" -H "Authorization: Bearer $K")
|
||||
mkdir -p "$OUT"
|
||||
curl -sS --fail "${H[@]}" "$U/rest/v1/" > "$OUT/openapi-schema.json"
|
||||
for t in $(jq -r '.paths | keys[] | select(. != "/" and (startswith("/rpc/")|not)) | ltrimstr("/")' "$OUT/openapi-schema.json"); do
|
||||
order=$(jq -r --arg t "$t" '.definitions[$t].properties | if has("id") then "&order=id.asc" else "" end' "$OUT/openapi-schema.json")
|
||||
off=0; : > "$OUT/$t.ndjson"
|
||||
while :; do
|
||||
page=$(curl -sS --fail "${H[@]}" "$U/rest/v1/$t?select=*$order&limit=$PAGE&offset=$off")
|
||||
n=$(jq 'length' <<<"$page"); jq -c '.[]' <<<"$page" >> "$OUT/$t.ndjson"
|
||||
(( n < PAGE )) && break; off=$((off+PAGE))
|
||||
done
|
||||
jq -s '.' "$OUT/$t.ndjson" > "$OUT/$t.json" && rm "$OUT/$t.ndjson"
|
||||
echo "supabase: $t $(jq length "$OUT/$t.json") rows"
|
||||
done
|
||||
Reference in New Issue
Block a user