This commit introduces a more reliable and consistent approach to setting up the development environment using backups: - Add setup-from-backup.sh script for environment setup from existing backups - Standardize script naming and organization - Move obsolete scripts to bin/obsolete directory - Update documentation with new workflow instructions - Create migration guide for transitioning to new workflow - Update Memory Bank with workflow improvements The new workflow provides: - More reliable environment setup - Faster setup process - Offline development capability - Consistent development environments across team members Breaking changes: - setup-dev.sh is replaced by setup-from-backup.sh - sync-and-setup.sh is replaced by separate scripts - verify-with-wpcli.sh is no longer used Migration path is documented in MIGRATION_GUIDE.md
88 lines
No EOL
2.4 KiB
Bash
Executable file
88 lines
No EOL
2.4 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Load environment variables from current directory
|
|
if [ ! -f .env ]; then
|
|
echo "Error: .env file not found in current directory!"
|
|
exit 1
|
|
fi
|
|
|
|
source .env
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
# Function to check if a command was successful
|
|
check_status() {
|
|
if [ $? -eq 0 ]; then
|
|
echo -e "${GREEN}✓ $1${NC}"
|
|
return 0
|
|
else
|
|
echo -e "${RED}✗ $1${NC}"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Create backup directory
|
|
BACKUP_DIR="backups/$(date +%Y%m%d_%H%M%S)"
|
|
mkdir -p "$BACKUP_DIR"
|
|
echo -e "${YELLOW}Creating backup in: $BACKUP_DIR${NC}"
|
|
|
|
# Test SSH connection
|
|
echo "Testing SSH connection..."
|
|
if ! ssh -q "$PROD_SSH_USER@$PROD_HOST" exit; then
|
|
echo -e "${RED}Error: Cannot connect to production server${NC}"
|
|
exit 1
|
|
fi
|
|
check_status "SSH connection test"
|
|
|
|
# Download WordPress files
|
|
echo "Downloading WordPress files..."
|
|
rsync -avz --exclude='wp-config.php' \
|
|
--exclude='.git/' \
|
|
--exclude='node_modules/' \
|
|
--exclude='*.log' \
|
|
--exclude='wp-content/cache/' \
|
|
--exclude='wp-content/uploads/cache/' \
|
|
"$PROD_SSH_USER@$PROD_HOST:$PROD_PATH/" "$BACKUP_DIR/wordpress/"
|
|
check_status "WordPress files download"
|
|
|
|
# Export and download database
|
|
echo "Exporting production database..."
|
|
ssh "$PROD_SSH_USER@$PROD_HOST" "cd $PROD_PATH && wp db export - --add-drop-table" > "$BACKUP_DIR/database.sql"
|
|
check_status "Database export"
|
|
|
|
# Download wp-config.php (for reference)
|
|
echo "Downloading wp-config.php..."
|
|
scp "$PROD_SSH_USER@$PROD_HOST:$PROD_PATH/wp-config.php" "$BACKUP_DIR/wp-config.php.prod"
|
|
check_status "wp-config.php download"
|
|
|
|
# Create manifest file
|
|
echo "Creating backup manifest..."
|
|
cat > "$BACKUP_DIR/manifest.txt" <<EOF
|
|
Production Backup Manifest
|
|
========================
|
|
Date: $(date)
|
|
Server: $PROD_HOST
|
|
WordPress Path: $PROD_PATH
|
|
Database: $PROD_DB_NAME
|
|
|
|
Environment Details:
|
|
- WordPress Version: $(ssh "$PROD_SSH_USER@$PROD_HOST" "cd $PROD_PATH && wp core version")
|
|
- PHP Version: $(ssh "$PROD_SSH_USER@$PROD_HOST" "php -v | head -n 1")
|
|
- MySQL Version: $(ssh "$PROD_SSH_USER@$PROD_HOST" "mysql -V")
|
|
|
|
Backup Contents:
|
|
- WordPress files (excluding wp-config.php, cache, etc.)
|
|
- Database dump (database.sql)
|
|
- Production wp-config.php (for reference)
|
|
EOF
|
|
|
|
# Create latest symlink
|
|
rm -f backups/latest
|
|
ln -s "$BACKUP_DIR" backups/latest
|
|
|
|
echo -e "${GREEN}Production sync completed successfully!${NC}"
|
|
echo "Backup stored in: $BACKUP_DIR" |