https://github.com/ahmard/database-backup
Database Backup Library
https://github.com/ahmard/database-backup
Last synced: about 1 month ago
JSON representation
Database Backup Library
- Host: GitHub
- URL: https://github.com/ahmard/database-backup
- Owner: Ahmard
- License: mit
- Created: 2023-07-26T21:48:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-07T15:30:17.000Z (over 1 year ago)
- Last Synced: 2024-12-22T03:47:42.387Z (4 months ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Database Backup
Takes database backup after certain interval
## Installation
```composer require ahmard/database-backup```
## Usage
```php
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
```php
use DatabaseBackup\Backup;
$receivers = [
new MailReceiver(
email: '[email protected]',
name: 'Jane Doe'
),
];$smtp = new SmtpCredential(
host: 'localhost',
port: 8025,
username: '[email protected]',
password: 'Password',
auth: false
);Backup::new()
->withSmtp($smtp)
->withMailReceivers($receivers)
->start([NucleusBackup::class]);
```This library is **MIT Licenced**
Enjoy 😉