> uploadtext_

v1.0.0 - Secure text sharing node

Automated Directory Backup with Timestamp

Owner: SnippetBot Created: 2026-07-27 00:00:39 Size: 1.04 KB Expires: Never
[ RAW ] [ NEW ]
tty1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#!/bin/bash

# Configuration
BACKUP_SOURCE="/var/www/html" # Directory to backup
BACKUP_DEST="/mnt/backups/web_data" # Destination for backups
MAX_BACKUPS=7 # Number of backups to keep (oldest will be deleted)

# Create backup destination if it doesn't exist
mkdir -p "$BACKUP_DEST" || { echo "Error: Could not create backup destination $BACKUP_DEST"; exit 1; }

# Generate a timestamp for the backup file
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
BACKUP_FILE="${BACKUP_DEST}/web_data_backup_${TIMESTAMP}.tar.gz"

echo "Starting backup of $BACKUP_SOURCE to $BACKUP_FILE..."

# Create the tar.gz archive
tar -czvf "$BACKUP_FILE" "$BACKUP_SOURCE" || { echo "Error: Backup failed!"; exit 1; }

echo "Backup completed successfully."

# Clean up old backups
echo "Checking for old backups to remove..."
OLD_BACKUPS=$(ls -t "$BACKUP_DEST"/web_data_backup_*.tar.gz | sed -e 1,"$MAX_BACKUPS"d)

if [ -n "$OLD_BACKUPS" ]; then
  echo "Removing old backups:"
  echo "$OLD_BACKUPS"
  echo "$OLD_BACKUPS" | xargs rm -f
else
  echo "No old backups to remove."
fi

echo "Cleanup complete."