Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions batch-mysql-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Batch MySQL Setup Script
# Usage: ./batch-mysql-setup.sh <hosts_file> <ssh_key>

set -e

if [ $# -lt 2 ]; then
echo "Usage: $0 <hosts_file> <ssh_key>"
echo "Example: $0 hosts.txt ~/.ssh/id_rsa"
exit 1
fi

HOSTS_FILE=$1
SSH_KEY=$2

if [ ! -f "$HOSTS_FILE" ]; then
echo "Hosts file $HOSTS_FILE not found!"
exit 1
fi

echo "Starting batch MySQL setup..."
echo "Hosts file: $HOSTS_FILE"
echo "SSH key: $SSH_KEY"
echo ""

# Read hosts and setup MySQL on each
while IFS= read -r host; do
if [ -n "$host" ] && [[ ! "$host" =~ ^# ]]; then
echo "Setting up MySQL on $host..."

# Use the remote setup script
./remote-mysql-setup.sh "$host" "$SSH_KEY" "myapp_db" "myapp_user" "SecurePassword123!"

echo "Completed setup on $host"
echo "----------------------------------------"
fi
done < "$HOSTS_FILE"

echo "Batch MySQL setup completed for all hosts!"
13 changes: 13 additions & 0 deletions hosts.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# List of Rocky Linux 9 hosts for MySQL setup
# Add your host IPs here, one per line
# Lines starting with # are comments and will be ignored

192.168.1.100
192.168.1.101
192.168.1.102
192.168.1.103

# Example hosts (uncomment and modify as needed):
# 10.0.0.10
# 10.0.0.11
# 10.0.0.12
25 changes: 25 additions & 0 deletions mysql-backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# MySQL Backup Script
# Usage: ./mysql-backup.sh [database_name]

DB_NAME=${1:-"myapp_db"}
BACKUP_DIR="/var/backups/mysql"
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="$BACKUP_DIR/${DB_NAME}_$DATE.sql"

# Create backup directory
sudo mkdir -p "$BACKUP_DIR"

# Create backup
mysqldump -u root -p"RootPassword123!" --single-transaction --routines --triggers "$DB_NAME" > "$BACKUP_FILE"

# Compress backup
gzip "$BACKUP_FILE"

echo "Backup created: ${BACKUP_FILE}.gz"

# Remove backups older than 7 days
find "$BACKUP_DIR" -name "*.sql.gz" -mtime +7 -delete

echo "Old backups cleaned up"
Loading