Files
kakeibo/scripts/backup-pull.sh
T
suphicakir e4c8d971fc feat(yedek): günlük MongoDB yedeği, geri yükleme ve bu bilgisayara kopya
- scripts/backup.sh: mongodump + bütünlük denetimi, son 14 yedek
- scripts/restore.sh: ayrı veritabanına geri yükleme ve sayım karşılaştırma
- scripts/backup-pull.sh + systemd zamanlayıcıları; kurulum docs/DEPLOY.md §6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:40:06 +03:00

42 lines
1.8 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.
#!/usr/bin/env bash
# Canlı yedekleri bu bilgisayara çeker (sunucu dışı kopya). systemd kullanıcı zamanlayıcısı çalıştırır;
# elle de çalıştırılabilir: scripts/backup-pull.sh
#
# KAKEIBO_BACKUP_HOST ~/.ssh/config'teki sunucu adı [atlas]
# REMOTE_DIR Sunucudaki yedek klasörü [/var/backups/kakeibo]
# LOCAL_DIR Bu bilgisayardaki klasör [~/Yedekler/kakeibo]
# KEEP Burada saklanacak yedek sayısı [60]
#
# En yeni yedek 2 günden eskiyse masaüstü bildirimi verir (sunucudaki günlük yedek durmuş olabilir).
set -euo pipefail
HOST=${KAKEIBO_BACKUP_HOST:-atlas}
REMOTE_DIR=${REMOTE_DIR:-/var/backups/kakeibo}
LOCAL_DIR=${LOCAL_DIR:-$HOME/Yedekler/kakeibo}
KEEP=${KEEP:-60}
warn() {
echo "[kakeibo-pull] UYARI: $*" >&2
command -v notify-send >/dev/null && notify-send -u critical "Kakeibo yedeği" "$*" || true
}
mkdir -p "$LOCAL_DIR"
chmod 700 "$LOCAL_DIR"
# Yalnızca tamamlanmış yedekler (.partial hariç); var olanlar yeniden indirilmez
if ! rsync -a --ignore-existing --include='*.archive.gz' --exclude='*' \
-e 'ssh -o BatchMode=yes -o ConnectTimeout=15' "$HOST:$REMOTE_DIR/" "$LOCAL_DIR/"; then
warn "sunucudan yedek çekilemedi ($HOST). Sunucu açık mı, SSH anahtarı çalışıyor mu?"
exit 1
fi
newest=$(ls -1t "$LOCAL_DIR"/*.archive.gz 2>/dev/null | head -n1 || true)
if [[ -z $newest ]]; then
warn "hiç yedek yok"
exit 1
fi
age_h=$(( ($(date +%s) - $(stat -c %Y "$newest")) / 3600 ))
echo "[kakeibo-pull] en yeni: $(basename "$newest") ($age_h saat önce)"
(( age_h <= 48 )) || warn "en yeni yedek $age_h saat önce alınmış; sunucudaki günlük yedeği kontrol edin."
ls -1t "$LOCAL_DIR"/*.archive.gz | tail -n +"$((KEEP + 1))" | while read -r f; do rm -f -- "$f"; done