spatie / laravel-backup

A package to backup your Laravel app

Home Page:https://spatie.be/docs/laravel-backup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The dump process failed with exitcode 2 : Misuse of shell builtins : mysqldump: Got error: 2004: "Can't create TCP/IP socket (10106)" when trying to connect

web-dev-nav opened this issue · comments

Hello Im using spatie/laravel-backup for manage backup on my project

When I want to backup via command line everything works fine via commands

php artisan backup:run or php artisan backup:run --only-db or php artisan backup:run --only-files

But when I execute any of these commands from the controller via Artisan:call('backup:run') method , I have the following error:

Exception message: The dump process failed with exitcode 2 : Misuse of shell builtins : mysqldump: Got error: 2004: Can't create TCP/IP socket (10106) when trying to connect

And its not just happened to me, many people are getting the same problem and have no solution for it, I already search the entire internet.

composer JSON

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.3.0",
        "doctrine/dbal": "^2.11",
        "fideloper/proxy": "^4.4",
        "gladcodes/keygen": "^1.1",
        "guzzlehttp/guzzle": "^7.0.1",
        "intervention/image": "^2.5",
        "kwn/number-to-words": "^1.12",
        "laravel/framework": "^8.65",
        "laravel/tinker": "^2.0",
        "laravel/ui": "3.0",
        "laravelcollective/html": "^6.2",
        "maatwebsite/excel": "^3.1",
        "milon/barcode": "^8.0",
        "spatie/db-dumper": "^2.21",
        "spatie/laravel-backup": "^6.16",
        "spatie/laravel-permission": "^3.17",
        "srmklive/paypal": "^3.0",
        "stripe/stripe-php": "^7.57",
        "twilio/sdk": "^6.10"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "^3.6",
        "facade/ignition": "^2.5",
        "fzaninotto/faker": "^1.9.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^5.10",
        "phpunit/phpunit": "^9.5.10"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

Same problem with spatie/db-dumper

Route::get('/export',function(){
		Spatie\DbDumper\Databases\MySql::create()
		->setDumpBinaryPath('C:\xampp\mysql\bin')
		->setDbName(env('DB_DATABASE'))
		->setUserName(env('DB_USERNAME'))
		->setPassword(env('DB_PASSWORD'))
		->setHost(env('DB_HOST'))
		->dumpToFile('dump.sql'); 
	});

Feel free to make a PR to fix it

Means that nobody else have the same problem or that nobody else are gonna make a fix for you, so, you could make a fix and support community or read old solutions instead of opening a new issue

Read this

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

->setDumpBinaryPath('C:\xampp\mysql\bin')

This backup package requires PHP 8.0, with the ZIP module and Laravel 9.0 or higher. It's not compatible with Windows.
https://spatie.be/docs/laravel-backup/v8/requirements

On linux everything is working

I completely understand, that I'm here using "spatie/laravel-backup": "^6.16" and on Command Line it's working perfectly, zip extension is also enabled and its successfully making zip backup....on windows the only issue is when we call it from route/controller.

Route::get('/backup', function (Request $request) {
   Artisan::call('backup:run');
   return Artisan::output();
});

As my problem is the same as this one: https://laracasts.com/discuss/channels/laravel/artisancallbackuprun-not-working

Windows is not supported according to the documentation, don't expect fixes for Windows, but you could do a PR for Windows as long as the original functionality is not affected

Ohky, I can see Thank you so much for the spatie packages!

I did test your example on Windows 10 with PHP 8.1 and MariaDB 10.6 and it is working without problems, maybe it is your implementation

Route::get('/export',function(){
  Spatie\DbDumper\Databases\MySql::create()
    ->setDumpBinaryPath('C:\xampp\mysql\bin')
    ->setDbName(env('DB_DATABASE'))
    ->setUserName(env('DB_USERNAME'))
    ->setPassword(env('DB_PASSWORD'))
    ->setHost(env('DB_HOST'))
    ->dumpToFile('dump.sql'); 
});

Also this works

Route::get('/backup', function (Request $request) {
   Artisan::call('backup:run');
   return Artisan::output();
});

I'm here using "spatie/laravel-backup": "^6.16"

I'm using spatie/laravel-backup:7.8.0
Laravel Backup 6.x and 7.x are not supported anymore, only 8.x

commented

1000+ people are getting the same problem

😄😄😄

already search the entire internet.

🤣🤣🤣

This problem can have a lot of caused, wrong permissions, wrong version numbers, ... Probably the package is not in error, but it's something in your environment.

If you find that there is a bug in our package, feel free to send a PR.

This problem can have a lot of caused, wrong permissions, wrong version numbers, ... Probably the package is not in error, but it's something in your environment.

If you find that there is a bug in our package, feel free to send a PR.

Yes you guys are right maybe it's a any of the issues that you mentioned, instead, I tried shell_exec and it worked.

Route::get('/export',function(){
	shell_exec("C:/xampp/mysql/bin/mysqldump -h localhost -u root test > C:/xampp/htdocs/projects/main.sql");
  });

Reference: https://stackoverflow.com/a/15294585/13804634

Hello Im using spatie/laravel-backup for manage backup on my project

When I want to backup via command line everything works fine via commands

php artisan backup:run or php artisan backup:run --only-db or php artisan backup:run --only-files

But when I execute any of these commands from the controller via Artisan:call('backup:run') method , I have the following error:

Exception message: The dump process failed with exitcode 2 : Misuse of shell builtins : mysqldump: Got error: 2004: Can't create TCP/IP socket (10106) when trying to connect

And its not just happened to me, many people are getting the same problem and have no solution for it, I already search the entire internet.

composer JSON

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.3.0",
        "doctrine/dbal": "^2.11",
        "fideloper/proxy": "^4.4",
        "gladcodes/keygen": "^1.1",
        "guzzlehttp/guzzle": "^7.0.1",
        "intervention/image": "^2.5",
        "kwn/number-to-words": "^1.12",
        "laravel/framework": "^8.65",
        "laravel/tinker": "^2.0",
        "laravel/ui": "3.0",
        "laravelcollective/html": "^6.2",
        "maatwebsite/excel": "^3.1",
        "milon/barcode": "^8.0",
        "spatie/db-dumper": "^2.21",
        "spatie/laravel-backup": "^6.16",
        "spatie/laravel-permission": "^3.17",
        "srmklive/paypal": "^3.0",
        "stripe/stripe-php": "^7.57",
        "twilio/sdk": "^6.10"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "^3.6",
        "facade/ignition": "^2.5",
        "fzaninotto/faker": "^1.9.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^5.10",
        "phpunit/phpunit": "^9.5.10"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

Same problem with spatie/db-dumper

Route::get('/export',function(){
		Spatie\DbDumper\Databases\MySql::create()
		->setDumpBinaryPath('C:\xampp\mysql\bin')
		->setDbName(env('DB_DATABASE'))
		->setUserName(env('DB_USERNAME'))
		->setPassword(env('DB_PASSWORD'))
		->setHost(env('DB_HOST'))
		->dumpToFile('dump.sql'); 
	});

Please share what solution you get ? I'm also facing same issue