1. Go to this page and download the library: Download deagel1337/backup-kit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
deagel1337 / backup-kit example snippets
eagel1337\Backup\Kit\Application\Backup\BackupMariaDbApplication;
use Deagel1337\Backup\Kit\DatabaseBackup\Driver\MariaDbBackupDriver;
use Deagel1337\Backup\Kit\DatabaseBackup\Model\DatabaseConnection;
use Deagel1337\Backup\Kit\Step\Backup\BackupDatabaseStep;
use Deagel1337\Backup\Kit\Step\Backup\CheckDiskSpaceStep;
$connection = new DatabaseConnection(
driver: 'mariadb',
host: getenv('DB_HOST') ?: '127.0.0.1',
port: (int) (getenv('DB_PORT') ?: 3306),
database: getenv('DB_DATABASE') ?: '',
username: getenv('DB_USERNAME') ?: '',
password: getenv('DB_PASSWORD') ?: '',
);
$driver = new MariaDbBackupDriver($connection);
$application = BackupMariaDbApplication::create([
new CheckDiskSpaceStep(),
new BackupDatabaseStep($driver),
]);
$dump = $application->run(__DIR__ . '/backup.sql');
echo "Dump erstellt: {$dump->path}\n";
use Deagel1337\Backup\Kit\Application\Backup\BackupApplication;
use Deagel1337\Backup\Kit\Archive\Driver\BorgArchiveDriver;
use Deagel1337\Backup\Kit\Archive\Model\RetentionPolicy;
use Deagel1337\Backup\Kit\Services\ArchiveService;
$databaseDriver = new MariaDbBackupDriver($connection);
$archiveService = new ArchiveService(new BorgArchiveDriver(
repository: getenv('BORG_REPOSITORY') ?: '',
passphrase: getenv('BORG_PASSPHRASE') ?: '',
));
$result = (new BackupApplication($databaseDriver, $archiveService))->run(
dumpPath: __DIR__ . '/backup.sql',
archiveName: 'backup-' . date('Y-m-d-H-i-s'),
files: [__DIR__ . '/data'],
retention: new RetentionPolicy(keepDaily: 7, keepWeekly: 4),
);
echo "Backup erstellt: {$result->archive->path}\n";
use Deagel1337\Backup\Kit\Application\Restore\RestoreMariaDbApplication;
use Deagel1337\Backup\Kit\DatabaseBackup\Model\DatabaseDump;
use Deagel1337\Backup\Kit\Step\Restore\CreateDatabaseBackupStep;
use Deagel1337\Backup\Kit\Step\Restore\RestoreDatabaseStep;
$databaseDriver = new MariaDbBackupDriver($connection);
$dump = new DatabaseDump(__DIR__ . '/backup.sql', 'mariadb', 'sql');
$databaseDriver->validateRequirements();
$databaseDriver->validateDump($dump);
$restore = RestoreMariaDbApplication::create($databaseDriver, [
new CreateDatabaseBackupStep($databaseDriver, __DIR__ . '/before-restore.sql'),
new RestoreDatabaseStep($databaseDriver),
]);
$restore->run($dump);