Docker deployment improvements: fixed backup/restore, sticky headers, quality code display
This commit is contained in:
@@ -104,11 +104,12 @@ class DatabaseBackupManager:
|
||||
# Build mysqldump command
|
||||
# Note: --skip-lock-tables and --force help with views that have permission issues
|
||||
cmd = [
|
||||
'mysqldump',
|
||||
'mariadb-dump',
|
||||
f"--host={self.config['host']}",
|
||||
f"--port={self.config['port']}",
|
||||
f"--user={self.config['user']}",
|
||||
f"--password={self.config['password']}",
|
||||
'--skip-ssl',
|
||||
'--single-transaction',
|
||||
'--skip-lock-tables',
|
||||
'--force',
|
||||
@@ -315,7 +316,7 @@ class DatabaseBackupManager:
|
||||
# --complete-insert: Include column names in INSERT (more reliable)
|
||||
# --extended-insert: Use multi-row INSERT for efficiency
|
||||
cmd = [
|
||||
'mysqldump',
|
||||
'mariadb-dump',
|
||||
f"--host={self.config['host']}",
|
||||
f"--port={self.config['port']}",
|
||||
f"--user={self.config['user']}",
|
||||
@@ -396,36 +397,43 @@ class DatabaseBackupManager:
|
||||
'message': 'Backup file not found'
|
||||
}
|
||||
|
||||
# Build mysql restore command
|
||||
cmd = [
|
||||
'mysql',
|
||||
f"--host={self.config['host']}",
|
||||
f"--port={self.config['port']}",
|
||||
f"--user={self.config['user']}",
|
||||
f"--password={self.config['password']}"
|
||||
]
|
||||
# Read SQL file and execute using Python mariadb library
|
||||
import mariadb
|
||||
|
||||
# Execute mysql restore
|
||||
with open(file_path, 'r') as f:
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
stdin=f,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True
|
||||
)
|
||||
sql_content = f.read()
|
||||
|
||||
if result.returncode == 0:
|
||||
return {
|
||||
'success': True,
|
||||
'message': f'Database restored successfully from {filename}'
|
||||
}
|
||||
else:
|
||||
error_msg = result.stderr
|
||||
print(f"Restore error: {error_msg}")
|
||||
return {
|
||||
'success': False,
|
||||
'message': f'Restore failed: {error_msg}'
|
||||
}
|
||||
# Connect to database
|
||||
conn = mariadb.connect(
|
||||
user=self.config['user'],
|
||||
password=self.config['password'],
|
||||
host=self.config['host'],
|
||||
port=int(self.config['port']),
|
||||
database=self.config['database']
|
||||
)
|
||||
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Split SQL into statements and execute
|
||||
statements = sql_content.split(';')
|
||||
executed = 0
|
||||
|
||||
for statement in statements:
|
||||
statement = statement.strip()
|
||||
if statement:
|
||||
try:
|
||||
cursor.execute(statement)
|
||||
executed += 1
|
||||
except Exception as stmt_error:
|
||||
print(f"Warning executing statement: {stmt_error}")
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return {
|
||||
'success': True,
|
||||
'message': f'Database restored successfully from {filename} ({executed} statements executed)'
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"Exception during restore: {e}")
|
||||
@@ -499,24 +507,34 @@ class DatabaseBackupManager:
|
||||
print(f"Warning during table truncation: {e}")
|
||||
# Continue anyway - the restore might still work
|
||||
|
||||
# Build mysql restore command for data
|
||||
cmd = [
|
||||
'mysql',
|
||||
f"--host={self.config['host']}",
|
||||
f"--port={self.config['port']}",
|
||||
f"--user={self.config['user']}",
|
||||
f"--password={self.config['password']}",
|
||||
self.config['database']
|
||||
]
|
||||
|
||||
# Execute mysql restore
|
||||
# Read and execute SQL file using Python mariadb library
|
||||
with open(file_path, 'r') as f:
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
stdin=f,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True
|
||||
)
|
||||
sql_content = f.read()
|
||||
|
||||
conn = mariadb.connect(
|
||||
user=self.config['user'],
|
||||
password=self.config['password'],
|
||||
host=self.config['host'],
|
||||
port=int(self.config['port']),
|
||||
database=self.config['database']
|
||||
)
|
||||
|
||||
cursor = conn.cursor()
|
||||
statements = sql_content.split(';')
|
||||
executed = 0
|
||||
|
||||
for statement in statements:
|
||||
statement = statement.strip()
|
||||
if statement:
|
||||
try:
|
||||
cursor.execute(statement)
|
||||
executed += 1
|
||||
except Exception as stmt_error:
|
||||
print(f"Warning executing statement: {stmt_error}")
|
||||
|
||||
conn.commit()
|
||||
result_success = True
|
||||
result_returncode = 0
|
||||
|
||||
# Re-enable foreign key checks
|
||||
try:
|
||||
@@ -535,17 +553,15 @@ class DatabaseBackupManager:
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not re-enable foreign key checks: {e}")
|
||||
|
||||
if result.returncode == 0:
|
||||
if result_success:
|
||||
return {
|
||||
'success': True,
|
||||
'message': f'Data restored successfully from {filename}'
|
||||
}
|
||||
else:
|
||||
error_msg = result.stderr
|
||||
print(f"Data restore error: {error_msg}")
|
||||
return {
|
||||
'success': False,
|
||||
'message': f'Data restore failed: {error_msg}'
|
||||
'message': f'Data restore failed'
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user