Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed PostgreSQL Backup Issue In Windows OS #915

Closed
AltiumWilliam opened this issue May 22, 2019 · 1 comment
Closed

Fixed PostgreSQL Backup Issue In Windows OS #915

AltiumWilliam opened this issue May 22, 2019 · 1 comment

Comments

@AltiumWilliam
Copy link

Laravel: v5.8
PHP: v7.2
DB: PostgreSQL v10
laravel-backup: v6.2
OS: Windows 10
I have same Issue , DB_Dumper could not find pg_dump. Even when I add pg_dump path to windows enviroment path variable. it does'nt work.
After two days work on it.I found a small bug.
Do these steps to fix problem.

  1. edit config/database.php:

      'pgsql' => [
         'driver' => 'pgsql',
         'host' => env('DB_HOST', '127.0.0.1'),
         'port' => env('DB_PORT', '5432'),
         'database' => env('DB_DATABASE', 'forge'),
         'username' => env('DB_USERNAME', 'forge'),
         'password' => env('DB_PASSWORD', ''),
         'charset' => 'utf8',
         'prefix' => '',
         'prefix_indexes' => true,
         'schema' => 'public',
         'sslmode' => 'prefer',
         'dump' => [  // Added
             'dump_binary_path' => env('PGSQL_DUMP_PATH'), 
             'use_single_transaction',
             'timeout' => 60 * 5, // 5 minute timeout
         ]
     ],
    
  2. edit .env file and add these lines to DB part:
    PGSQL_DUMP_PATH="C:\\Program Files\\PostgreSQL\\10\\bin"
    MYSQL_DUMP_PATH="C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin"

notice that I use \\ instead of \ or /

The BUG part

  1. edit vendor\spatie\db-dumper\src\Databases\PostgreSql.php

`

public function getDumpCommand(string $dumpFile): string
{
	$quote = $this->determineQuote();                       // Added
	$command = [
		"{$quote}{$this->dumpBinaryPath}pg_dump{$quote}",   // Edited
		"-U {$this->userName}",
		'-h '.($this->socket === '' ? $this->host : $this->socket),
		"-p {$this->port}",
	];
	if ($this->useInserts) {
		$command[] = '--inserts';
	}
	foreach ($this->extraOptions as $extraOption) {
		$command[] = $extraOption;
	}
	if (! empty($this->includeTables)) {
		$command[] = '-t '.implode(' -t ', $this->includeTables);
	}
	if (! empty($this->excludeTables)) {
		$command[] = '-T '.implode(' -T ', $this->excludeTables);
	}
	return $this->echoToFile(implode(' ', $command), $dumpFile);
}
protected function determineQuote(): string     // Added
{
	return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? '"' : "'";
}

these code was in mysql driver but there is not in pgsql driver. I add them and problem fixed.

Originally posted by @AltiumWilliam in #526 (comment)

@spatie-bot
Copy link

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants