Files
ukaiautomation/backup-and-commit.sh
2025-06-08 11:21:30 +01:00

68 lines
1.8 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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!"