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

[2.2.1] Magento Database Backup Command Fails (Fix included) #12877

Closed
azeemism opened this issue Dec 25, 2017 · 7 comments
Closed

[2.2.1] Magento Database Backup Command Fails (Fix included) #12877

azeemism opened this issue Dec 25, 2017 · 7 comments
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@azeemism
Copy link

The magento backup command fails under magento 2.2.1. There was no such issue under magento 2.1.8. They are no errors in the database log.

Preconditions

  1. Magento composer install
www-data@skynet:~/example.com/magento/2.x/2.x$ php bin/magento -V
Magento CLI version 2.2.1
  1. Using MariaDB
root@skynet:~/.admin/scripts# dpkg -l | grep mariadb
ii  libmariadbclient18                   10.1.30+maria-1~jessie               amd64        MariaDB database client library
ii  mariadb-client                       10.1.30+maria-1~jessie               all          MariaDB database client (metapackage depending on the latest version)
ii  mariadb-client-10.1                  10.1.30+maria-1~jessie               amd64        MariaDB database client binaries
ii  mariadb-client-core-10.1             10.1.30+maria-1~jessie               amd64        MariaDB database core client binaries
ii  mariadb-common                       10.1.30+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/conf.d/mariadb.cnf)
ii  mariadb-server                       10.1.30+maria-1~jessie               all          MariaDB database server (metapackage depending on the latest version)
ii  mariadb-server-10.1                  10.1.30+maria-1~jessie               amd64        MariaDB database server binaries
ii  mariadb-server-core-10.1             10.1.30+maria-1~jessie               amd64        MariaDB database core server files
root@skynet:~/.admin/scripts# dpkg -l | grep mysql
ii  dovecot-mysql                        1:2.2.13-12~deb8u3                   amd64        secure POP3/IMAP server - MySQL support
ii  libclass-dbi-mysql-perl              1.00-3                               all          extensions to Class::DBI for MySQL
ii  libdbd-mysql-perl                    4.028-2+deb8u2                       amd64        Perl5 database interface to the MySQL database
ii  libmysqlclient18                     10.1.30+maria-1~jessie               amd64        Virtual package to satisfy external depends
ii  libqt4-sql-mysql:amd64               4:4.8.6+git64-g5dc8b2b+dfsg-3+deb8u1 amd64        Qt 4 MySQL database driver
ii  libtime-piece-mysql-perl             0.06-2                               all          module adding MySQL-specific methods to Time::Piece
ii  mariadb-common                       10.1.30+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/conf.d/mariadb.cnf)
ii  mysql-common                         10.1.30+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/my.cnf)
ii  php5-mysqlnd                         5.6.30+dfsg-0+deb8u1                 amd64        MySQL module for php5 (Native Driver)
ii  php7.0-mysql                         7.0.26-1~dotdeb+8.2                  amd64        MySQL module for PHP
ii  postfix-mysql                        2.11.3-1+deb8u2                      amd64        MySQL map support for Postfix
ii  roundcube-mysql                      1.2.3+dfsg.1-4+deb9u1                all          metapackage providing MySQL dependencies for RoundCube
  1. Using PHP7
root@skynet:~/.admin/scripts# dpkg -l | grep php7
rc  libapache2-mod-php7.0                7.0.14-1~dotdeb+8.1                  amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php7.0                               7.0.26-1~dotdeb+8.2                  all          server-side, HTML-embedded scripting language (metapackage)
ii  php7.0-bcmath                        7.0.26-1~dotdeb+8.2                  amd64        Bcmath module for PHP
ii  php7.0-cli                           7.0.26-1~dotdeb+8.2                  amd64        command-line interpreter for the PHP scripting language
ii  php7.0-common                        7.0.26-1~dotdeb+8.2                  amd64        documentation, examples and common module for PHP
ii  php7.0-curl                          7.0.26-1~dotdeb+8.2                  amd64        CURL module for PHP
ii  php7.0-dev                           7.0.26-1~dotdeb+8.2                  amd64        Files for PHP7.0 module development
ii  php7.0-fpm                           7.0.26-1~dotdeb+8.2                  amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php7.0-gd                            7.0.26-1~dotdeb+8.2                  amd64        GD module for PHP
ii  php7.0-igbinary                      2.0.1-1~dotdeb+8.1                   amd64        igbinary serializer for PHP
ii  php7.0-imagick                       3.4.3-1~dotdeb+8.1                   amd64        Provides a wrapper to the ImageMagick library
ii  php7.0-intl                          7.0.26-1~dotdeb+8.2                  amd64        Internationalisation module for PHP
ii  php7.0-json                          7.0.26-1~dotdeb+8.2                  amd64        JSON module for PHP
ii  php7.0-mbstring                      7.0.26-1~dotdeb+8.2                  amd64        MBSTRING module for PHP
ii  php7.0-mcrypt                        7.0.26-1~dotdeb+8.2                  amd64        libmcrypt module for PHP
ii  php7.0-mysql                         7.0.26-1~dotdeb+8.2                  amd64        MySQL module for PHP
ii  php7.0-opcache                       7.0.26-1~dotdeb+8.2                  amd64        Zend OpCache module for PHP
ii  php7.0-pspell                        7.0.26-1~dotdeb+8.2                  amd64        pspell module for PHP
ii  php7.0-readline                      7.0.26-1~dotdeb+8.2                  amd64        readline module for PHP
ii  php7.0-redis                         3.1.3-1~dotdeb+8.1                   amd64        PHP extension for interfacing with Redis
ii  php7.0-soap                          7.0.26-1~dotdeb+8.2                  amd64        SOAP module for PHP
ii  php7.0-xml                           7.0.26-1~dotdeb+8.2                  amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP
ii  php7.0-xmlrpc                        7.0.26-1~dotdeb+8.2                  amd64        XMLRPC-EPI module for PHP
ii  php7.0-xsl                           7.0.26-1~dotdeb+8.2                  all          XSL module for PHP (dummy)
ii  php7.0-zip                           7.0.26-1~dotdeb+8.2                  amd64        Zip module for PHP

  1. OS
root@skynet:~/.admin/scripts# uname -a
Linux skynet 3.16.0-4-amd64 #1 SMP Debian 3.16.51-2 (2017-12-03) x86_64 GNU/Linux
  1. composer.json
{
    "name": "magento/project-community-edition",
    "description": "eCommerce Platform for Growth (Community Edition)",
    "type": "project",
    "version": "2.1.1",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "require": {
        "magento/product-community-edition": "2.2.1",
        "composer/composer": "@alpha",
        "magento/magento-composer-installer": "^0.1.12",
        "geoip2/geoip2": "^2.4",
        "webshopapps/module-matrixrate": "^20.1"
    },
    "require-dev": {
        "phpunit/phpunit": "4.1.0",
        "squizlabs/php_codesniffer": "1.5.3",
        "phpmd/phpmd": "@stable",
        "pdepend/pdepend": "2.2.2",
        "fabpot/php-cs-fixer": "~1.2",
        "lusitanian/oauth": "~0.3 <=0.7.0",
        "sebastian/phpcpd": "2.0.0"
    },
    "config": {
        "use-include-path": true
    },
    "autoload": {
        "psr-4": {
            "Magento\\Framework\\": "lib/internal/Magento/Framework/",
            "Magento\\Setup\\": "setup/src/Magento/Setup/",
            "Magento\\": "app/code/Magento/"
        },
        "psr-0": {
            "": "app/code/"
        },
        "files": [
            "app/etc/NonComposerComponentRegistration.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/",
            "Magento\\Tools\\": "dev/tools/Magento/Tools/",
            "Magento\\Tools\\Sanity\\": "dev/build/publication/sanity/Magento/Tools/Sanity/",
            "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/",
            "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/"
        }
    },
    "minimum-stability": "alpha",
    "prefer-stable": true,
    "repositories": [
        {
            "type": "composer",
            "url": "https://repo.magento.com/"
        }
    ],
    "extra": {
        "magento-force": "override"
    }
}

Steps to reproduce

  1. php bin/magento setup:backup --code --media --db
  2. php bin/magento setup:backup --db

Expected result

  1. [SUCCESS]: DB backup completed successfully.

Actual result

www-data@skynet:~/example.com/magento/2.x/2.x$ php bin/magento setup:backup --code --media --db

Enabling maintenance mode
Code backup is starting...
Code backup filename: 1514213089_filesystem_code.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Code backup path: /var/www/example.com/magento/2.x/2.x/var/backups/1514213089_filesystem_code.tgz
[SUCCESS]: Code backup completed successfully.
Media backup is starting...
Media backup filename: 1514213089_filesystem_media.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Media backup path: /var/www/example.com/magento/2.x/2.x/var/backups/1514213089_filesystem_media.tgz
[SUCCESS]: Media backup completed successfully.
DB backup is starting...
Warning: Division by zero in /var/www/example.com/magento/2.x/2.x/vendor/magento/module-backup/Model/Db.php on line 157
Disabling maintenance mode
PHP Fatal error:  Uncaught Exception: User Error: Some transactions have not been committed or rolled back in /var/www/example.com/magento/2.x/2.x/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 3864 in /var/www/example.com/magento/2.x/2.x/vendor/magento/framework/App/ErrorHandler.php:61
Stack trace:
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(256, 'Some transactio...', '/var/www/vitami...', 3864, Array)
#1 /var/www/example.com/magento/2.x/2.x/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(3864): trigger_error('Some transactio...', 256)
#2 [internal function]: Magento\Framework\DB\Adapter\Pdo\Mysql->__destruct()
#3 {main}
  thrown in /var/www/example.com/magento/2.x/2.x/vendor/magento/framework/App/ErrorHandler.php on line 61
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Dec 25, 2017
@azeemism
Copy link
Author

Possible fix mentioned by ChrisK on Feb 8 at 6:51
https://magento.stackexchange.com/questions/141087/warning-division-by-zero-in-var-www-magento-vendor-magento-module-backup-model

Looks like the db dump crashed while trying to add rows for or around "importexport_importdata" table

A quick glance it looks like a small issue with not checking for a non-zero denominator.

The code/file in question is: https://github.com/magento/magento2/blob/2.2/app/code/Magento/Backup/Model/Db.php#L157

ChrisK indicated that he managed to fix the issue by overriding/localing the file and modifying the line

$limit = floor(self::BUFFER_LENGTH / $tableStatus->getAvgRowLength());

to

$limit = floor(self::BUFFER_LENGTH / max($tableStatus->getAvgRowLength(), 1));

And keeping the rest intact

@azeemism
Copy link
Author

azeemism commented Dec 25, 2017

The Database backup completes successfully after making the change:

www-data@skynet:~/example.com/magento/2.x/2.x$ nano /var/www/vitaminwebstore.com/magento/2.x/2.x/vendor/magento/module-backup/Model/Db.php

Replace Line 157:
$limit = floor(self::BUFFER_LENGTH / $tableStatus->getAvgRowLength());

With:
$limit = floor(self::BUFFER_LENGTH / max($tableStatus->getAvgRowLength(), 1));

www-data@skynet:~/example.com/magento/2.x/2.x$ php bin/magento setup:backup --db

Enabling maintenance mode
DB backup is starting...
DB backup filename: 1514217168_db.sql
DB backup path: /var/www/example.com/magento/2.x/2.x/var/backups/1514217168_db.sql
[SUCCESS]: DB backup completed successfully.
Disabling maintenance mode

Please update the code/file with this fix: https://github.com/magento/magento2/blob/2.2/app/code/Magento/Backup/Model/Db.php#L157

@azeemism azeemism changed the title [2.2.1] Magento Database Backup Command Fails [2.2.1] Magento Database Backup Command Fails (Fix included) Dec 25, 2017
@PieterCappelle
Copy link
Contributor

@azeemism Could you create PR please? Thanks!

@azeemism
Copy link
Author

azeemism commented Jan 7, 2018

Hi @PieterCappelle , I have never created a PR before. I am not sure how to create one.

@jagritijoshi
Copy link

I am fixing this issue as per @azeemism and creating a pull request #mm18in

jagritijoshi pushed a commit to jagritijoshi/magento2 that referenced this issue Jan 9, 2018
jagritijoshi added a commit to jagritijoshi/magento2 that referenced this issue Jan 9, 2018
@ishakhsuvarov
Copy link
Contributor

Hi @azeemism. Thank you for your report.
The issue has been fixed in #13066 by @jagritijoshi in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

@ishakhsuvarov ishakhsuvarov added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Jan 16, 2018
magento-team pushed a commit that referenced this issue Jan 16, 2018
 - Merge Pull Request #13066 from jagritijoshi/magento2:2.2-develop
 - Merged commits:
   1. bc434c1
@magento-engcom-team
Copy link
Contributor

Hi @azeemism. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1302 by @magento-engcom-team in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Jan 29, 2018
coderimus pushed a commit to coderimus/magento2 that referenced this issue Jan 29, 2018
Applied pull request patch https://github.com/magento/magento2/pull/13066.patch (created by @jagritijoshi) based on commit(s):
  1. bc434c1

Fixed GitHub Issues in 2.3-develop branch:
  - magento#12877: [2.2.1] Magento Database Backup Command Fails (Fix included) (reported by @azeemism)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests

5 participants