PHP Classes


Recommend this page to a friend!
  Classes of Ahmad Mustapha   PHP Database Backup   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Database Backup
Take a database backup periodically
Author: By
Last change:
Date: 2 months ago
Size: 1,849 bytes


Class file image Download

Database Backup

Takes database backup after certain interval


## 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
    Console::info('nucleus backup completed');

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';


Console::writeln("Backup service started");

// Run backups Backup::new()->start([NucleusBackup::class]);

### Mail Notification

use DatabaseBackup\Backup;

$receivers = [

new MailReceiver(
    email: '',
    name: 'Jane Doe'


$smtp = new SmtpCredential(

host: 'localhost',
port: 8025,Helpers
username: '',
password: 'Password',
auth: false




This library is MIT Licenced

Enjoy ?