Files
MathApp/ops/applogs/pull-app-logs.sh

27 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# روی ۲۴۷، هر ساعت (zareian-applog-pull.timer). بایگانیِ فشرده‌ی لاگِ برنامه را از ۲۴۹ می‌گیرد و
# **برای همیشه** در ~/zareian-pgbackup/app-logs/ نگه می‌دارد (تصمیمِ مالک ۲۰۲۶-۱۰-۱۳؛ برآورد حدودِ ۱ گیگ در سال
# با ۶۰۰ کاربرِ فعال). هیچ فایلی این‌جا پاک نمی‌شود. کلید فقط serve-archive.sh را اجرا می‌کند.
set -euo pipefail
DEST=/home/administrator/zareian-pgbackup/app-logs
mkdir -p "$DEST"
r() { ssh -i /home/administrator/.ssh/zareian_applogs -o BatchMode=yes -o ConnectTimeout=20 \
administrator@192.168.200.164 "$@"; }
free_kb=$(df --output=avail -k "$DEST" | tail -1)
[ "$free_kb" -gt 3000000 ] || { echo "disk too full ($free_kb KB free); skipping" >&2; exit 1; }
got=0
for name in $(r list); do
[[ "$name" =~ ^app-[0-9]{8}T[0-9]{6}Z(-old[0-9]+)?\.log\.gz$ ]] || { echo "skip odd name: $name" >&2; continue; }
if [ ! -s "$DEST/$name" ]; then
r get "$name" > "$DEST/.$name.part"
gzip -t "$DEST/.$name.part"
chmod 600 "$DEST/.$name.part"
mv "$DEST/.$name.part" "$DEST/$name"
got=$((got + 1))
fi
r ack "$name"
done
echo "fetched $got new; $(ls "$DEST" | wc -l) files, $(du -sh "$DEST" | cut -f1) in $DEST"