ahmard / database-backup
Handles database backup
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^8.2
- phpmailer/phpmailer: ^6.8
- spatie/db-dumper: ^3.3
Requires (Dev)
- openswoole/ide-helper: ^4.11
- phpstan/phpstan: ^1.10
This package is not auto-updated.
Last update: 2024-11-15 03:57:21 UTC
README
Takes database backup after certain interval
Installation
composer require ahmard/database-backup
Usage
use DatabaseBackup\Backup; use DatabaseBackup\Helpers\Console; // Backup Class (NucleusBackup.php) class NucleusBackup extends AbstractBackup { protected bool $sendMailOnError = false; protected bool $sendMailOnSuccess = false; public function interval(): int { return 2_000; } public function filePath(): string { return sprintf('%s/nucleus-%s.sql', dirname(__DIR__, 2), uniqid()); } public function onSuccess(string $path, callable $done): void { $done(); Console::info('nucleus backup completed'); unlink($path); } public function connection(): DatabaseConnection { return new DatabaseConnection( driver: DatabaseDriver::MYSQL, host: 'localhost', username: 'root', password: '1234', database: 'nucleus' ); } } // Runner (run.php) use Swoole\Runtime; use DatabaseBackup\Backup; use DatabaseBackup\Helpers\Console; require __DIR__ . '/vendor/autoload.php'; Runtime::enableCoroutine(SWOOLE_HOOK_ALL); Console::writeln("Backup service started"); // Run backups Backup::new()->start([NucleusBackup::class]);
Mail Notification
use DatabaseBackup\Backup; $receivers = [ new MailReceiver( email: 'jane.doe@example.com', name: 'Jane Doe' ), ]; $smtp = new SmtpCredential( host: 'localhost', port: 8025, username: 'noreply@example.com', password: 'Password', auth: false ); Backup::new() ->withSmtp($smtp) ->withMailReceivers($receivers) ->start([NucleusBackup::class]);
This library is MIT Licenced
Enjoy 😉