Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"


MYSQL_DUMP_BINARY_PATH=
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,24 @@ Clone the repository
```bash
composer create-project rupadana/remote-database-backup
```

Update your local environment

```bash
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=mysql_backup
DB_USERNAME=postgres
DB_PASSWORD=
```
if you use `mysql` as your database and get this error `mysqldump: command not found` or not save file, you must update your `.env` file with this configuration for example os x m1

```bash
MYSQL_DUMP_BINARY_PATH="/opt/homebrew/bin/"
```


Run artisan `app:install`

```bash
Expand Down
52 changes: 52 additions & 0 deletions app/Filament/Resources/DatabaseResource/Actions/DatabaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace App\Filament\Resources\DatabaseResource\Actions;

use App\Models\Database;
use Filament\Actions\Action;
use Exception;
use Filament\Notifications\Notification;
use mysqli;

class DatabaseTest extends Action
{
protected function setUp(): void
{
parent::setUp();
$this->name('test-database-connection');

$this->action(function (Database $record) {

$record = $record->data[0]['data'];


$host = $record['host'];
$username = $record['username'];
$password = $record['password'];
$database = $record['database'];
$port = $record['port'];

$mysqli = new \mysqli($host, $username, $password, $database);

// Check if the query was successful
if ($mysqli->connect_error) {
$this->failureNotification(
Notification::make()
->title("Connection Failed")
->body($mysqli->error)
);
$this->sendFailureNotification();
}else{
$this->sendSuccessNotification();
$mysqli->close();
}
});

$this->label('Test Connection');
$this->color('info');

// Here we use the record's ID
$this->successNotificationTitle('Connection OK ');


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protected function getHeaderActions(): array
{
return [
DatabaseResource\Actions\DatabaseBackupPageAction::make(),
DatabaseResource\Actions\DatabaseTest::make(),
Actions\DeleteAction::make(),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ public function run(): array
// Define the path to store the backup
$path = storage_path().'/databases';

$mysqlDumpPath = config('database.connections.mysql.dump.dump_binary_path');

// Construct the command to perform the backup
$command = 'mysqldump --user='.$options['username'].
$command = $mysqlDumpPath.'mysqldump --user='.$options['username'].
' --password='.$options['password'].
' --host='.$options['host'].
' '.$options['database'].
' | gzip > '.$path.'/'.$filename;
' | gzip > '.$path.'/'.$filename.' --no-tablespaces';

// Execute the backup command

exec($command);

// Return the path and filename of the backup
Expand Down
5 changes: 5 additions & 0 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'dump' => [
'dump_binary_path' => env('MYSQL_DUMP_BINARY_PATH', ''),
'use_single_transaction' => true,
'timeout' => env('MYSQL_DUMP_TIMEOUT', 300), // default : 5 minute timeout
],
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
Expand Down