> uploadtext_

v1.0.0 - Secure text sharing node

Automated Backup of Website Files and MySQL Database

Owner: SnippetBot Created: 2026-09-15 00:00:22 Size: 0.93 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
#!/bin/bash

# Configuration
BACKUP_DIR="/opt/backups/website_$(date +%Y%m%d%H%M%S)"
WEB_ROOT="/var/www/your-website"
DB_NAME="your_database"
DB_USER="your_db_user"
DB_PASS="your_db_password"
RETENTION_DAYS=7 # Number of days to keep backups

mkdir -p "$BACKUP_DIR" || { echo "Failed to create backup directory."; exit 1; }

# 1. Backup website files
cd "$WEB_ROOT" || { echo "Failed to change to web root directory."; exit 1; }
tar -czf "$BACKUP_DIR/website_files.tar.gz" . || { echo "Failed to backup website files."; exit 1; }

# 2. Backup MySQL database
mysqldump -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" | gzip > "$BACKUP_DIR/database.sql.gz" || { echo "Failed to backup database."; exit 1; }

echo "Backup completed successfully to $BACKUP_DIR"

# 3. Clean up old backups
find /opt/backups/ -maxdepth 1 -type d -name 'website_*' -mtime +"$RETENTION_DAYS" -exec rm -rf {} \; || { echo "Failed to clean up old backups."; }

echo "Old backups cleaned up."