diff --git a/backup_trilium.sh b/backup_trilium.sh index f25a2e8..157661f 100644 --- a/backup_trilium.sh +++ b/backup_trilium.sh @@ -50,6 +50,22 @@ cd $DEST || exit 1 ls -1t trilium_*.db 2>/dev/null | tail -n +$((GARDER+1)) | while read f; do rm -f "$f"; done chmod 600 "$CIBLE" +# 5. Push off-site vers Proton Drive (n echoue PAS le backup local si KO) +REMOTE="proton:Backups/trilium" +OFFSITE="offsite:KO" +if command -v rclone >/dev/null 2>&1; then + if rclone copy "$CIBLE" "$REMOTE/" --max-duration 5m >/dev/null 2>&1; then + # rotation distante : garder les N plus recents + rclone lsf "$REMOTE/" 2>/dev/null | grep '^trilium_.*\.db$' | sort -r | tail -n +$((GARDER+1)) | while read f; do + rclone deletefile "$REMOTE/$f" >/dev/null 2>&1 + done + NBREMOTE=$(rclone lsf "$REMOTE/" 2>/dev/null | grep -c '^trilium_.*\.db$') + OFFSITE="offsite:OK($NBREMOTE)" + fi +else + OFFSITE="offsite:rclone-absent" +fi + TAILLE=$(du -h "$CIBLE" | cut -f1) RESTANT=$(ls -1 trilium_*.db 2>/dev/null | wc -l) -echo "OK $CIBLE ($TAILLE, $NBNOTES notes, $RESTANT backups conserves)" +echo "OK $CIBLE ($TAILLE, $NBNOTES notes, $RESTANT locaux, $OFFSITE)"