PHP Classes

PHP Database Backup: Take a database backup periodically

Recommend this page to a friend!

  Author Author  
Picture of Ahmad Mustapha
Name: Ahmad Mustapha <contact>
Classes: 23 packages by
Country: Nigeria Nigeria
Age: ???
All time rank: 236214 in Nigeria Nigeria
Week rank: 1 Up
Innovation award
Innovation award
Nominee: 9x


  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
This package can take a database backup periodically.

It can take an object with functions that define the parameters of the backup to be processed, like the interval period between each backup, the database backup file pattern, the database connection, and a function to call when a backup process succeeds.

The package will automatically execute the backup process at the defined periods.


Details

Database Backup

Takes database backup after certain interval

Installation


## 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,Helpers
username: 'noreply@example.com',
password: 'Password',
auth: false

);

Backup::new()

->withSmtp($smtp)
->withMailReceivers($receivers)
->start([NucleusBackup::class]);

This library is MIT Licenced

Enjoy ?

  Classes of Ahmad Mustapha  >  PHP Database Backup  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog (1)  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP Database Backup
Base name: database-backup
Description: Take a database backup periodically
Version: 1.0.0
PHP version: 8
License: Shareware
All time users: 124 users
All time rank: 9387
Week users: 124 users
Week rank: 1 Up
 
  Groups   Rate classes User ratings   Applications   Files Files  

  Groups  
Group folder image Databases Database management, accessing and searching View top rated classes
Group folder image Systems administration System configuration and management View top rated classes
Group folder image PHP 8 Classes using PHP 8 specific features View top rated classes


  User ratings  
Not yet rated by the users

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder imagesrc (8 files, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageHelpers (1 file)
Files folder imageServices (2 files)
  Plain text file AbstractBackup.php Class Class source
  Plain text file Backup.php Class Class source
  Plain text file Coroutine.php Class Class source
  Plain text file DatabaseConnection.php Class Class source
  Accessible without login Plain text file DatabaseDriver.php Aux. Auxiliary script
  Plain text file MailReceiver.php Class Class source
  Plain text file NoSmtp.php Class Class source
  Plain text file SmtpCredential.php Class Class source

  Files folder image Files  /  src  /  Helpers  
File Role Description
  Plain text file Console.php Class Class source

  Files folder image Files  /  src  /  Services  
File Role Description
  Plain text file BackupService.php Class Class source
  Plain text file MailService.php Class Class source

Install with Composer Install with Composer - Download Download all files: database-backup.tar.gz database-backup.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
  Files folder image Files  
File Role Description
Files folder imagesrc (8 files, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageHelpers (1 file)
Files folder imageServices (2 files)
  Plain text file AbstractBackup.php Class Class source
  Plain text file Backup.php Class Class source
  Plain text file Coroutine.php Class Class source
  Plain text file DatabaseConnection.php Class Class source
  Accessible without login Plain text file DatabaseDriver.php Aux. Auxiliary script
  Plain text file MailReceiver.php Class Class source
  Plain text file NoSmtp.php Class Class source
  Plain text file SmtpCredential.php Class Class source

  Files folder image Files  /  src  /  Helpers  
File Role Description
  Plain text file Console.php Class Class source

  Files folder image Files  /  src  /  Services  
File Role Description
  Plain text file BackupService.php Class Class source
  Plain text file MailService.php Class Class source

Install with Composer Install with Composer - Download Download all files: database-backup.tar.gz database-backup.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.