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

Laravel 5.4, Spatie backup v3/4, Homestead on Windows 10 - pg_dump'' is not recognized as an internal or external command, #526

Closed
PhPPgAdminBug opened this issue Sep 24, 2017 · 3 comments

Comments

@PhPPgAdminBug
Copy link

PhPPgAdminBug commented Sep 24, 2017

ERRORS
`$ php artisan backup:run
Starting backup...

[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: Too few arguments to function Spatie\DbDumper\DbDumper::excludeTables(), 0 passed in C:\Users\BonBon\Code\vendor\spatie\laravel-backup\src\Tasks\Backup\DbDumperFactory.php on line 102 and exactly 1 expected

BonBon@DESKTOP-DOK1CL5 MINGW64 ~/Code (master)
$ php artisan backup:run
Starting backup...
Dumping database grabgg...
Backup failed because The dump process failed with exitcode 1 : General error : ''pg_dump'' is not recognized as an internal or external command,
operable program or batch file.
.
#0 C:\Users\BonBon\Code\vendor\spatie\db-dumper\src\DbDumper.php(222): Spatie\DbDumper\Exceptions\DumpFailed::processDidNotEndSuccessfully(Object(Symfony\Component\Process\Process))
#1 C:\Users\BonBon\Code\vendor\spatie\db-dumper\src\Databases\PostgreSql.php(55): Spatie\DbDumper\DbDumper->checkIfDumpWasSuccessFul(Object(Symfony\Component\Process\Process), 'C:\Users\BonBon...')
#2 C:\Users\BonBon\Code\vendor\spatie\laravel-backup\src\Tasks\Backup\BackupJob.php(219): Spatie\DbDumper\Databases\PostgreSql->dumpToFile('C:\Users\BonBon...')
#3 [internal function]: Spatie\Backup\Tasks\Backup\BackupJob->Spatie\Backup\Tasks\Backup{closure}(Object(Spatie\DbDumper\Databases\PostgreSql), 0)
#4 C:\Users\BonBon\Code\vendor\laravel\framework\src\Illuminate\Support\Collection.php(766): array_map(Object(Closure), Array, Array)
#5 C:\Users\BonBon\Code\vendor\spatie\laravel-backup\src\Tasks\Backup\BackupJob.php(230): Illuminate\Support\Collection->map(Object(Closure))
#6 C:\Users\BonBon\Code\vendor\spatie\laravel-backup\src\Tasks\Backup\BackupJob.php(149): Spatie\Backup\Tasks\Backup\BackupJob->dumpDatabases()
#7 C:\Users\BonBon\Code\vendor\spatie\laravel-backup\src\Tasks\Backup\BackupJob.php(129): Spatie\Backup\Tasks\Backup\BackupJob->createBackupManifest()
#8 C:\Users\BonBon\Code\vendor\spatie\laravel-backup\src\Commands\BackupCommand.php(49): Spatie\Backup\Tasks\Backup\BackupJob->run()
#9 [internal function]: Spatie\Backup\Commands\BackupCommand->handle()
#10 C:\Users\BonBon\Code\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#11 C:\Users\BonBon\Code\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container{closure}()
#12 C:\Users\BonBon\Code\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#13 C:\Users\BonBon\Code\vendor\laravel\framework\src\Illuminate\Container\Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#14 C:\Users\BonBon\Code\vendor\laravel\framework\src\Illuminate\Console\Command.php(182): Illuminate\Container\Container->call(Array)
#15 C:\Users\BonBon\Code\vendor\symfony\console\Command\Command.php(264): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#16 C:\Users\BonBon\Code\vendor\laravel\framework\src\Illuminate\Console\Command.php(167): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#17 C:\Users\BonBon\Code\vendor\spatie\laravel-backup\src\Commands\BaseCommand.php(22): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 C:\Users\BonBon\Code\vendor\symfony\console\Application.php(888): Spatie\Backup\Commands\BaseCommand->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 C:\Users\BonBon\Code\vendor\symfony\console\Application.php(224): Symfony\Component\Console\Application->doRunCommand(Object(Spatie\Backup\Commands\BackupCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\Co
nsoleOutput))
#20 C:\Users\BonBon\Code\vendor\symfony\console\Application.php(125): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 C:\Users\BonBon\Code\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(122): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 C:\Users\BonBon\Code\artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 {main}
Backup failed because: Expected response code 250 but got code "554", with message "554 Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings.
".

[Swift_TransportException]
Expected response code 250 but got code "554", with message "554 Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings.
"`

Configs
`<?php

return [

'backup' => [

    'name' => env('APP_URL'),

    'source' => [

        'files' => [

            'include' => [
                base_path(),
            ],

            'exclude' => [
                base_path('vendor'),
                base_path('node_modules'),
            ],

            'followLinks' => false,
        ],

        'databases' => [
            'pgsql',
        ],
    ],

    'gzip_database_dump' => false,

    'destination' => [

        'filename_prefix' => '',

        'disks' => [
            'local',
        ],
    ],
],

'notifications' => [

    'notifications' => [
        \Spatie\Backup\Notifications\Notifications\BackupHasFailed::class         => ['mail'],
        \Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFound::class => ['mail'],
        \Spatie\Backup\Notifications\Notifications\CleanupHasFailed::class        => ['mail'],
        \Spatie\Backup\Notifications\Notifications\BackupWasSuccessful::class     => ['mail'],
        \Spatie\Backup\Notifications\Notifications\HealthyBackupWasFound::class   => ['mail'],
        \Spatie\Backup\Notifications\Notifications\CleanupWasSuccessful::class    => ['mail'],
    ],

    'notifiable' => \Spatie\Backup\Notifications\Notifiable::class,

    'mail' => [
        'to' => '[email protected]',
    ],

    'slack' => [
        'webhook_url' => '',

        'channel' => null,
    ],
],

'monitorBackups' => [
    [
        'name' => env('APP_URL'),
        'disks' => ['local'],
        'newestBackupsShouldNotBeOlderThanDays' => 1,
        'storageUsedMayNotBeHigherThanMegabytes' => 5000,
    ],

],

'cleanup' => [
  
    'strategy' => \Spatie\Backup\Tasks\Cleanup\Strategies\DefaultStrategy::class,

    'defaultStrategy' => [

        'keepAllBackupsForDays' => 7,

        'keepDailyBackupsForDays' => 16,

        'keepWeeklyBackupsForWeeks' => 8,

        'keepMonthlyBackupsForMonths' => 4,

        'keepYearlyBackupsForYears' => 2,

        'deleteOldestBackupsWhenUsingMoreMegabytesThan' => 5000,
    ],
],

];
`

Database
'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' => '', 'schema' => 'public', 'sslmode' => 'prefer', // 'dump' => [ // 'dump_binary_path' => '/path/to/the/binary', // only the path, so withoutmysqldumporpg_dump // 'use_single_transaction', // 'timeout' => 60 * 5, // 5 minute timeout // 'exclude_tables' => [], // 'add_extra_option' => '--optionname=optionvalue', // ] ],

I have installed Vagrant Homestead x64 for Windows 10 Pro.
Did not installed any more, not binaries or else like this StackOverflow

Want to configure for every couple hours make PostgreSQL database backup, in case we need to restore it.

@PhPPgAdminBug PhPPgAdminBug changed the title Homestead PostgreSQL pg_dump Homestead - pg_dump'' is not recognized as an internal or external command, Sep 24, 2017
@PhPPgAdminBug PhPPgAdminBug changed the title Homestead - pg_dump'' is not recognized as an internal or external command, Homestead on Windows 10 - pg_dump'' is not recognized as an internal or external command, Sep 24, 2017
@PhPPgAdminBug PhPPgAdminBug changed the title Homestead on Windows 10 - pg_dump'' is not recognized as an internal or external command, Laravel 5.4, Homestead on Windows 10 - pg_dump'' is not recognized as an internal or external command, Sep 24, 2017
@PhPPgAdminBug PhPPgAdminBug changed the title Laravel 5.4, Homestead on Windows 10 - pg_dump'' is not recognized as an internal or external command, Laravel 5.4, backup v3/4 Homestead on Windows 10 - pg_dump'' is not recognized as an internal or external command, Sep 24, 2017
@PhPPgAdminBug PhPPgAdminBug changed the title Laravel 5.4, backup v3/4 Homestead on Windows 10 - pg_dump'' is not recognized as an internal or external command, Laravel 5.4, Spatie backup v3/4, Homestead on Windows 10 - pg_dump'' is not recognized as an internal or external command, Sep 24, 2017
@freekmurze
Copy link
Member

I'm guessing this is caused because pg_dump is not available in the environment you're running the backups.

@PhPPgAdminBug
Copy link
Author

PhPPgAdminBug commented Sep 26, 2017

yeah, thank you very much! On my Debian 9 it works great. Cool package.

P.S. Do not use Windows for development :D

@AltiumWilliam
Copy link

AltiumWilliam commented May 22, 2019

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.

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

3 participants