Backup database and code changes - 2025-06-08 13:21:22
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
#!/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!"
|
||||
39
backup-db-commit.sh
Executable file
39
backup-db-commit.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Database configuration
|
||||
DB_USER="root"
|
||||
DB_PASS="Piglet1969!!"
|
||||
DB_NAME="ukdataservices"
|
||||
DB_HOST="localhost"
|
||||
|
||||
# Backup filename with timestamp
|
||||
BACKUP_FILE="db_backup_$(date +%y%m%d_%H%M%S).sql"
|
||||
|
||||
echo "Starting database backup..."
|
||||
|
||||
# Create database backup
|
||||
mysqldump -u"$DB_USER" -p"$DB_PASS" -h"$DB_HOST" "$DB_NAME" > "$BACKUP_FILE"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Database backup created: $BACKUP_FILE"
|
||||
|
||||
# Add all changes to git
|
||||
echo "Adding changes to git..."
|
||||
git add -A
|
||||
|
||||
# Commit with timestamp
|
||||
COMMIT_MSG="Backup database and code changes - $(date '+%Y-%m-%d %H:%M:%S')"
|
||||
git commit -m "$COMMIT_MSG"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Changes committed successfully!"
|
||||
echo "Commit message: $COMMIT_MSG"
|
||||
else
|
||||
echo "No changes to commit or commit failed"
|
||||
fi
|
||||
else
|
||||
echo "Database backup failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Script completed."
|
||||
0
db_backup_250608_132015.sql
Normal file
0
db_backup_250608_132015.sql
Normal file
0
db_backup_250608_132054.sql
Normal file
0
db_backup_250608_132054.sql
Normal file
700
db_backup_250608_132122.sql
Normal file
700
db_backup_250608_132122.sql
Normal file
File diff suppressed because one or more lines are too long
0
new_backup_080625.sql
Normal file
0
new_backup_080625.sql
Normal file
Reference in New Issue
Block a user