Skip to main content

Code that compiles on the first try! CodeWithMpia wishes you very happy holidays.✨

Aller au contenu principal

Script Bash de sauvegarde automatique avec rotation

Script de backup compressé avec suppression automatique des anciennes sauvegardes au-delà de 7 jours.

Langage

bash

Accès

Libre

#!/bin/bash
# Automated backup script with rotation
BACKUP_DIR="/backups"
SOURCE="/data"
DAYS_TO_KEEP=7

# Create timestamped backup
timestamp=$(date +%Y%m%d_%H%M%S)
tar -czf "$BACKUP_DIR/backup_$timestamp.tar.gz" "$SOURCE"

# Remove backups older than DAYS_TO_KEEP
find "$BACKUP_DIR" -name "backup_*.tar.gz" -mtime +$DAYS_TO_KEEP -delete

Plus de snippets bash