PHP code example of julio101290 / postgresql-backup-manager
1. Go to this page and download the library: Download julio101290/postgresql-backup-manager 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/ */
julio101290 / postgresql-backup-manager example snippets
use PostgresqlBackupManager\PostgreSQLBackup;
$pdo = new PDO("pgsql:host=localhost;port=5432;dbname=mi_base", "usuario", "contraseña");
$backup = new PostgreSQLBackup(
$pdo,
'mi_base',
'usuario',
'contraseña',
'localhost',
5432,
__DIR__ . '/backups'
);
$archivoSQL = $backup->backup(); // Sin compresión
$archivoZip = $backup->backup(true); // Con compresión ZIP
$backup->restore('/ruta/al/respaldo.sql');
$backup->restore('/ruta/al/respaldo.sql.zip'); // Si está comprimido
public function restaurar($uuid) {
$info = $this->backups->where('uuid', $uuid)->first();
$config = config('Database')->default;
$pdo = new \PDO("pgsql:host={$config['hostname']};port={$config['port']};dbname={$config['database']}",
$config['username'], $config['password']);
$backup = new PostgreSQLBackup(
$pdo,
$config['database'],
$config['username'],
$config['password'],
$config['hostname'],
$config['port']
);
try {
$backup->restore($info['SQLFile']);
return $this->respondCreated(true, lang("backups.msg.restored"));
} catch (Exception $e) {
return $this->failServerError('Error al restaurar: ' . $e->getMessage());
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.