@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
|
||||
$app = require dirname(__DIR__).'/bootstrap/app.php';
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
|
||||
if (Illuminate\Support\Facades\DB::connection()->getDatabaseName() !== 'investemoz') {
|
||||
fwrite(STDERR, "Refusing unexpected active database target.\n");
|
||||
exit(20);
|
||||
}
|
||||
|
||||
$config = config('database.connections.pgsql');
|
||||
$command = [
|
||||
'C:/Program Files/PostgreSQL/17/bin/pg_dump.exe', '--host='.$config['host'], '--port='.$config['port'],
|
||||
'--username='.$config['username'], '--format=custom', '--no-owner', '--no-privileges', '--file='.$argv[1],
|
||||
$config['database'],
|
||||
];
|
||||
$environment = getenv();
|
||||
$environment['PGPASSWORD'] = $config['password'];
|
||||
$pipes = [];
|
||||
$process = proc_open($command, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes,
|
||||
dirname(__DIR__), $environment, ['bypass_shell' => true]);
|
||||
fclose($pipes[0]);
|
||||
$stdout = stream_get_contents($pipes[1]);
|
||||
fclose($pipes[1]);
|
||||
$stderr = stream_get_contents($pipes[2]);
|
||||
fclose($pipes[2]);
|
||||
$exitCode = proc_close($process);
|
||||
|
||||
if ($exitCode !== 0) {
|
||||
fwrite(STDERR, "pg_dump failed: ".trim($stderr)."\n");
|
||||
exit($exitCode);
|
||||
}
|
||||
|
||||
echo "Backup completed for investemoz.\n";
|
||||
Reference in New Issue
Block a user