PHP Classes

PHP Database Backup: Take a database backup periodically

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 195 All time: 8,533 This week: 82Up
Version License PHP version Categories
database-backup 1.0.0Shareware8Databases, Systems administration, PHP 8
Description 

Author

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.

Innovation Award
PHP Programming Innovation award nominee
September 2023
Number 6
Every project that uses a database should implement a backup process to ensure that it is possible to recover the database contents when something terrible happens that may cause loss of information.

Backup processes should be performed regularly so it is possible to recover a version of the database contents that is the most recent as possible in case it is necessary to restore the database contents from the latest backup.

This package can take regular backups with a given interval period defined only in PHP.

Manuel Lemos
Picture of Ahmad Mustapha
Name: Ahmad Mustapha <contact>
Classes: 24 packages by
Country: Nigeria Nigeria
Age: ???
All time rank: 226511 in Nigeria Nigeria
Week rank: 14 Up2 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 9x

Documentation

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 ?

  Files folder image Files (15)  
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 (15)  /  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 (15)  /  src  /  Helpers  
File Role Description
  Plain text file Console.php Class Class source

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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:195
This week:0
All time:8,533
This week:82Up