Files
CompanySite/scripts/backup/cleanup-old.sh
T
Clintchiz d402256547
Deploy to Production / Build & Verify (push) Failing after 5m56s
Ping Search Engines / Notify Search Engines (push) Successful in 2s
Deploy to Production / Pre-Deploy Tests (push) Has been skipped
Deploy to Production / Deploy to Railway (push) Has been skipped
Deploy to Production / Deploy to Render (push) Has been skipped
Deploy to Production / Deploy to VPS (PM2) (push) Has been skipped
Deploy to Production / Deploy to Fly.io (push) Has been skipped
Deploy to Production / Post-Deploy Verification (push) Has been skipped
Deploy to Production / Notify on Failure (push) Successful in 2s
E2E Test Suite / Critical User Journeys (push) Has been skipped
E2E Test Suite / API Integration Tests (push) Has been skipped
E2E Test Suite / Smoke Tests (P0) (push) Failing after 11m26s
E2E Test Suite / Form Interaction Tests (push) Failing after 11m42s
E2E Test Suite / Destructive & Chaos Tests (push) Failing after 12m2s
E2E Test Suite / Cross-Browser Regression (chromium) (push) Failing after 16m14s
E2E Test Suite / Cross-Browser Regression (webkit) (push) Failing after 17m45s
E2E Test Suite / Cross-Browser Regression (firefox) (push) Failing after 25m23s
E2E Test Suite / Security Header Tests (push) Failing after 7m55s
E2E Test Suite / Test Report Summary (push) Failing after 20s
E2E Test Suite / Mobile Device Tests (push) Failing after 2h49m9s
Uptime Monitor / Health & Response Time (push) Failing after 2s
Uptime Monitor / SSL Certificate (push) Successful in 2s
Uptime Monitor / Send Alerts (push) Failing after 3s
Uptime Monitor / Record Uptime Success (push) Has been skipped
First Init
2026-03-21 16:46:46 +05:30

101 lines
3.7 KiB
Bash

#!/bin/bash
# Cleanup Old Backups Script
# Enforces retention policy across all backup types
set -e
# Configuration
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
BACKUP_ROOT="$PROJECT_ROOT/backups"
LOG_FILE="$BACKUP_ROOT/cleanup.log"
# Retention periods (in days)
DAILY_RETENTION=7
INCREMENTAL_RETENTION=3
SAFETY_RETENTION=30
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
log() {
echo "[$(date +"%Y-%m-%d %H:%M:%S")] $1" | tee -a "$LOG_FILE"
}
log "${YELLOW}Starting backup cleanup...${NC}"
# Daily backups - keep last 7
if [ -d "$BACKUP_ROOT/daily" ]; then
log "Cleaning daily backups (keeping last $DAILY_RETENTION)..."
cd "$BACKUP_ROOT/daily"
DELETED=$(ls -t full-backup-*.tar.gz 2>/dev/null | tail -n +$((DAILY_RETENTION + 1)) | wc -l)
ls -t full-backup-*.tar.gz 2>/dev/null | tail -n +$((DAILY_RETENTION + 1)) | xargs -r rm -f
log " Deleted $DELETED daily backups"
fi
# Weekly backups - keep last 4
if [ -d "$BACKUP_ROOT/weekly" ]; then
log "Cleaning weekly backups (keeping last 4)..."
cd "$BACKUP_ROOT/weekly"
DELETED=$(ls -t weekly-backup-*.tar.gz 2>/dev/null | tail -n +5 | wc -l)
ls -t weekly-backup-*.tar.gz 2>/dev/null | tail -n +5 | xargs -r rm -f
log " Deleted $DELETED weekly backups"
fi
# Monthly backups - keep last 3
if [ -d "$BACKUP_ROOT/monthly" ]; then
log "Cleaning monthly backups (keeping last 3)..."
cd "$BACKUP_ROOT/monthly"
DELETED=$(ls -t monthly-backup-*.tar.gz 2>/dev/null | tail -n +4 | wc -l)
ls -t monthly-backup-*.tar.gz 2>/dev/null | tail -n +4 | xargs -r rm -f
log " Deleted $DELETED monthly backups"
fi
# Incremental backups - keep last 3 days
if [ -d "$BACKUP_ROOT/incremental" ]; then
log "Cleaning incremental backups (keeping last $INCREMENTAL_RETENTION days)..."
cd "$BACKUP_ROOT/incremental"
DELETED=$(find . -name "content-*.tar.gz" -type f -mtime +$INCREMENTAL_RETENTION 2>/dev/null | wc -l)
find . -name "content-*.tar.gz" -type f -mtime +$INCREMENTAL_RETENTION -delete 2>/dev/null || true
log " Deleted $DELETED incremental backups"
fi
# Pre-deploy config backups - keep last 10
if [ -d "$BACKUP_ROOT/pre-deploy" ]; then
log "Cleaning pre-deploy backups (keeping last 10)..."
cd "$BACKUP_ROOT/pre-deploy"
DELETED=$(ls -t config-*.tar.gz 2>/dev/null | tail -n +11 | wc -l)
ls -t config-*.tar.gz 2>/dev/null | tail -n +11 | xargs -r rm -f
log " Deleted $DELETED pre-deploy backups"
fi
# Safety backups - keep last 30 days
if [ -d "$BACKUP_ROOT/safety" ]; then
log "Cleaning safety backups (keeping last $SAFETY_RETENTION days)..."
cd "$BACKUP_ROOT/safety"
DELETED=$(find . -name "pre-restore-*.tar.gz" -type f -mtime +$SAFETY_RETENTION 2>/dev/null | wc -l)
find . -name "pre-restore-*.tar.gz" -type f -mtime +$SAFETY_RETENTION -delete 2>/dev/null || true
log " Deleted $DELETED safety backups"
fi
# Report storage usage
log "Current backup storage usage:"
du -sh "$BACKUP_ROOT"/* 2>/dev/null | tee -a "$LOG_FILE" || true
# Check for large backups (>500MB)
log "Checking for large backups (>500MB)..."
find "$BACKUP_ROOT" -name "*.tar.gz" -type f -size +500M -exec ls -lh {} \; 2>/dev/null | tee -a "$LOG_FILE" || true
log "${GREEN}Cleanup completed${NC}"
# Summary
echo ""
echo -e "${GREEN}=== Cleanup Summary ===${NC}"
echo -e "Total backup storage: $(du -sh $BACKUP_ROOT | cut -f1)"
echo -e "Daily backups: $(ls $BACKUP_ROOT/daily/*.tar.gz 2>/dev/null | wc -l)"
echo -e "Weekly backups: $(ls $BACKUP_ROOT/weekly/*.tar.gz 2>/dev/null | wc -l)"
echo -e "Monthly backups: $(ls $BACKUP_ROOT/monthly/*.tar.gz 2>/dev/null | wc -l)"
echo -e "Pre-deploy backups: $(ls $BACKUP_ROOT/pre-deploy/*.tar.gz 2>/dev/null | wc -l)"