ops: fix data/ triple-duplication costing ~24 GB on VPS
astro build resolves the public/data symlink and copies all activity JSON into dist/; rsync then copied that to the webroot — but nginx already serves /data/ directly from /var/bincio/data/ via alias, so both copies were dead weight. Freed 36 GB → 14 GB on the live server. - post-receive hook: prune dist/data/ before rsync, add --exclude=data/ - docs: update manual rebuild command and nginx comment to match - serve/server.py: _mb() now uses lstat() to count symlinks at face value rather than following them to targets, so admin storage panel no longer double-counts _merged/ (which is mostly symlinks into activities/)
This commit is contained in:
@@ -594,7 +594,9 @@ async def admin_disk(bincio_session: Optional[str] = Cookie(default=None)) -> JS
|
|||||||
def _mb(path: Path) -> float:
|
def _mb(path: Path) -> float:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return 0.0
|
return 0.0
|
||||||
total = sum(f.stat().st_size for f in path.rglob("*") if f.is_file())
|
# Use lstat to count symlink entries (few bytes each) rather than following
|
||||||
|
# the link to the target — prevents _merged/ from double-counting activities/.
|
||||||
|
total = sum(f.lstat().st_size for f in path.rglob("*") if f.is_file() or f.is_symlink())
|
||||||
return round(total / 1_048_576, 1)
|
return round(total / 1_048_576, 1)
|
||||||
|
|
||||||
def _count(path: Path, pattern: str = "*") -> int:
|
def _count(path: Path, pattern: str = "*") -> int:
|
||||||
@@ -991,7 +993,7 @@ async def me_storage(bincio_session: Optional[str] = Cookie(default=None)) -> JS
|
|||||||
def _mb(path: Path) -> float:
|
def _mb(path: Path) -> float:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return 0.0
|
return 0.0
|
||||||
total = sum(f.stat().st_size for f in path.rglob("*") if f.is_file())
|
total = sum(f.lstat().st_size for f in path.rglob("*") if f.is_file() or f.is_symlink())
|
||||||
return round(total / 1_048_576, 2)
|
return round(total / 1_048_576, 2)
|
||||||
|
|
||||||
def _count(path: Path, pattern: str = "*") -> int:
|
def _count(path: Path, pattern: str = "*") -> int:
|
||||||
|
|||||||
+11
-2
@@ -68,8 +68,11 @@ while read oldrev newrev refname; do
|
|||||||
cd $DEPLOY
|
cd $DEPLOY
|
||||||
~/.local/bin/uv run bincio render --data-dir $DATA --site-dir $DEPLOY/site
|
~/.local/bin/uv run bincio render --data-dir $DATA --site-dir $DEPLOY/site
|
||||||
|
|
||||||
|
echo "--- Pruning dist/data (nginx serves /data/ directly from $DATA) ---"
|
||||||
|
rm -rf $DEPLOY/site/dist/data
|
||||||
|
|
||||||
echo "--- Copying dist to webroot ---"
|
echo "--- Copying dist to webroot ---"
|
||||||
rsync -a --delete $DEPLOY/site/dist/ /var/www/bincio/
|
rsync -a --delete --exclude=data/ $DEPLOY/site/dist/ /var/www/bincio/
|
||||||
|
|
||||||
echo "--- Restarting API ---"
|
echo "--- Restarting API ---"
|
||||||
systemctl restart bincio || echo "WARNING: bincio service restart failed — check journalctl -u bincio"
|
systemctl restart bincio || echo "WARNING: bincio service restart failed — check journalctl -u bincio"
|
||||||
@@ -223,7 +226,8 @@ ssh root@<vps> "cd /opt/bincio && uv run bincio extract"
|
|||||||
# rebuild site
|
# rebuild site
|
||||||
ssh root@<vps> "cd /opt/bincio && \
|
ssh root@<vps> "cd /opt/bincio && \
|
||||||
uv run bincio render --data-dir /var/bincio/data --site-dir site && \
|
uv run bincio render --data-dir /var/bincio/data --site-dir site && \
|
||||||
rsync -a --delete site/dist/ /var/www/bincio/"
|
rm -rf site/dist/data && \
|
||||||
|
rsync -a --delete --exclude=data/ site/dist/ /var/www/bincio/"
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -253,6 +257,11 @@ server {
|
|||||||
|
|
||||||
# Data files served live from disk — bypasses the build/rsync cycle
|
# Data files served live from disk — bypasses the build/rsync cycle
|
||||||
# so uploads and merges are visible immediately without a site rebuild.
|
# so uploads and merges are visible immediately without a site rebuild.
|
||||||
|
#
|
||||||
|
# IMPORTANT: because nginx owns /data/ here, the post-receive hook must
|
||||||
|
# delete dist/data/ before rsyncing to the webroot. Otherwise astro build
|
||||||
|
# copies all activity JSON (GBs) into dist/ and rsync duplicates it again.
|
||||||
|
# The hook already does this; manual rebuilds must do the same.
|
||||||
location /data/ {
|
location /data/ {
|
||||||
alias /var/bincio/data/;
|
alias /var/bincio/data/;
|
||||||
add_header Cache-Control "no-cache, must-revalidate";
|
add_header Cache-Control "no-cache, must-revalidate";
|
||||||
|
|||||||
Reference in New Issue
Block a user