Many blog changes
This commit is contained in:
67
backup-and-commit.sh
Normal file
67
backup-and-commit.sh
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Database backup and commit script for UK Data Services
|
||||
# This script creates a database backup, adds it to git, and commits all changes
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
# Configuration
|
||||
DB_CONTAINER="ukdataservices-db"
|
||||
DB_NAME="ukdataservices"
|
||||
DB_USER="root"
|
||||
DB_PASSWORD="Piglet1969!!"
|
||||
TIMESTAMP=$(date +"%d%m%y_%H%M%S")
|
||||
BACKUP_FILE="db_backup_${TIMESTAMP}.sql"
|
||||
|
||||
echo "🔄 Starting database backup and commit process..."
|
||||
|
||||
# Check if database container is running
|
||||
if ! docker ps | grep -q $DB_CONTAINER; then
|
||||
echo "❌ Error: Database container '$DB_CONTAINER' is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "📦 Creating database backup: $BACKUP_FILE"
|
||||
|
||||
# Create database backup
|
||||
docker exec $DB_CONTAINER mysqldump -u$DB_USER -p$DB_PASSWORD --single-transaction --routines --triggers $DB_NAME > $BACKUP_FILE
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ Database backup created successfully: $BACKUP_FILE"
|
||||
echo "📊 Backup file size: $(du -h $BACKUP_FILE | cut -f1)"
|
||||
else
|
||||
echo "❌ Error: Failed to create database backup"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Add backup file to git
|
||||
echo "📝 Adding backup file to git repository..."
|
||||
git add $BACKUP_FILE
|
||||
|
||||
# Add all other changes to git
|
||||
echo "📝 Adding all changes to git repository..."
|
||||
git add .
|
||||
|
||||
# Check if there are any changes to commit
|
||||
if git diff --cached --quiet; then
|
||||
echo "ℹ️ No changes to commit"
|
||||
else
|
||||
# Create commit message with timestamp and backup info
|
||||
COMMIT_MSG="Database backup and updates - $(date '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
- Added database backup: $BACKUP_FILE
|
||||
- Committed all pending changes
|
||||
|
||||
🤖 Generated with Claude Code
|
||||
|
||||
Co-Authored-By: Claude <noreply@anthropic.com>"
|
||||
|
||||
echo "💾 Committing changes..."
|
||||
git commit -m "$COMMIT_MSG"
|
||||
|
||||
echo "✅ All changes committed successfully!"
|
||||
echo "📋 Commit details:"
|
||||
git log --oneline -1
|
||||
fi
|
||||
|
||||
echo "🎉 Backup and commit process completed!"
|
||||
Reference in New Issue
Block a user