-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated initial docker compose scripts for production env
- Loading branch information
1 parent
c2c59eb
commit d7838b8
Showing
15 changed files
with
3,132 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ | |
*.txt | ||
!mysql-init/init.sql | ||
!/ai/chat/requirements.txt | ||
/ai/venv | ||
/ai/venv | ||
/api/database/backups/ | ||
/ssl/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
$hardcodedPassword = 'me@dereja'; | ||
|
||
if (!isset($_POST['password']) || $_POST['password'] !== $hardcodedPassword) { | ||
http_response_code(403); | ||
echo json_encode(['success' => false, 'message' => 'Invalid password']); | ||
exit; | ||
} | ||
|
||
// Database connection details | ||
$dbHost = '192.168.160.4'; | ||
$dbUser = 'merqderejadb'; | ||
$dbPassword = 'merqderejadb'; | ||
$dbName = 'merqderejadb'; | ||
|
||
// Docker container name | ||
$containerName = 'merq_dereja_postgres'; | ||
|
||
// Directory to store backups | ||
$backupDir = './backups'; | ||
if (!is_dir($backupDir)) { | ||
mkdir($backupDir, 0777, true); // Create directory if it doesn't exist | ||
} | ||
|
||
// Backup file name with timestamp | ||
$backupFile = 'derejame_mb_backup_' . date('Ymd_His') . '.sql'; | ||
$backupFilePath = "$backupDir/$backupFile"; | ||
|
||
// Command to execute pg_dump inside the Docker container | ||
$command = "docker exec $containerName sh -c \"PGPASSWORD='$dbPassword' pg_dump -h $dbHost -U $dbUser -d $dbName -F c -b -v -f /tmp/$backupFile\" && docker cp $containerName:/tmp/$backupFile $backupFilePath"; | ||
|
||
// Execute the command | ||
$output = []; | ||
$return_var = 0; | ||
exec($command . ' 2>&1', $output, $return_var); | ||
|
||
if ($return_var === 0) { | ||
// Prepare backup details for the response | ||
$backupDetails = [ | ||
'name' => $backupFile, | ||
'date' => date('Y-m-d H:i:s'), | ||
'size' => filesize($backupFilePath), | ||
'path' => $backupFilePath // Ensure this path is correct and accessible | ||
]; | ||
|
||
// Send JSON response with success status and redirect URL | ||
echo json_encode(['success' => true, 'newBackup' => $backupDetails, 'redirect' => 'mb.php']); | ||
} else { | ||
http_response_code(500); | ||
echo json_encode(['success' => false, 'message' => 'Error creating backup.']); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
$hardcodedPassword = 'me@dereja'; | ||
|
||
if (!isset($_POST['password']) || $_POST['password'] !== $hardcodedPassword) { | ||
http_response_code(403); | ||
echo json_encode(['success' => false, 'message' => 'Invalid password']); | ||
exit; | ||
} | ||
|
||
$backupDir = './backups'; | ||
|
||
// Check if action and backups are set | ||
if (isset($_POST['action']) && $_POST['action'] == 'delete' && isset($_POST['backups'])) { | ||
$backupsToDelete = $_POST['backups']; | ||
|
||
foreach ($backupsToDelete as $backupName) { | ||
$filePath = "$backupDir/" . basename($backupName); | ||
if (file_exists($filePath)) { | ||
unlink($filePath); | ||
} | ||
} | ||
|
||
header("Location: mb.php?msg=deleted"); | ||
exit(); | ||
} | ||
|
||
header("Location: mb.php"); | ||
exit(); | ||
?> |
Oops, something went wrong.