在本教程中,我们将讨论如何在命令行系列中备份/回滚Db,媒体,代码。如您所知,在Magento 2中,它们在中添加了许多命令bin/magento
。这可能很难解决,让我解释一下有关如何备份/回滚Db,媒体,代码的更多细节。
目录
- 如何备份/回滚Db,媒体,代码命令行
- 列出所有存在的备份文件
- 备份资料库
- 备份媒体
- 备用码
- 如何回滚数据库,媒体,代码
- 列出所有存在的备份文件
- 注意
如何备份/回滚Db,媒体,代码命令行
转到Magento管理员根文件夹并显示用法:
php bin/magento setup:backup --help
Usage:
setup:backup [options]
Options:
--code Take code and configuration files backup (excluding temporary files)
--media Take media backup
--db Take complete database backup
--magento-init-params=MAGENTO-INIT-PARAMS Add to any command to customize Magento initialization parameters
For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.c
m&MAGE_DIRS[cache][path]=/var/tmp/cache"
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbos output and 3 for debug
Help:
Takes backup of Magento Application code base, media and database
列出所有存在的备份文件
php bin/magento info:backups:list
输出:
Showing backup files in /var/www/html/sam/ce2252/var/backups.
+---------------------------------+-------------+
| Backup Filename | Backup Type |
+---------------------------------+-------------+
| 1534245793_db.sql | db |
| 1534245893_filesystem_media.tgz | media |
+---------------------------------+-------------+
有2个备份文件:数据库和媒体。
备份资料库
此命令行将备份当前数据库并保存到静态文件。您可以存储在服务器上,上传到云或下载到本地计算机。
php bin/magento setup:backup --db
输出:
Enabling maintenance mode
DB backup is starting...
DB backup filename: 1534245793_db.sql
DB backup path: ./var/backups/1534245793_db.sql
[SUCCESS]: DB backup completed successfully.
Disabling maintenance mode
让我详细说明一下。在此过程的开始,它将进入维护模式,然后开始备份,然后存储到./var/backups/
文件夹中。之后,它将再次禁用维护模式。
您可以每天使用cron job设置运行备份数据库。请参阅以下示例:
crontab -e
它将显示服务器的当前cron作业表。让我们添加一个cron作业行:
0 0 * * * php /path/to/magento/bin/magento setup:backup --db
更改/path/to/magento/
为您的服务器路径。该计划任务将在每天的00:00运行。
备份媒体
与备份数据库相同
php bin/magento setup:backup --media
输出:
Enabling maintenance mode
Media backup is starting...
Media backup filename: 1534245893_filesystem_media.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Media backup path: ./var/backups/1534245893_filesystem_media.tgz
[SUCCESS]: Media backup completed successfully.
Disabling maintenance mode
备用码
与备份数据库,媒体相同
php bin/magento setup:backup --code
输出:
Enabling maintenance mode
Code backup is starting...
Code backup filename: 1534246155_filesystem_code.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Code backup path: ./var/backups/1534246155_filesystem_code.tgz
[SUCCESS]: Code backup completed successfully.
Disabling maintenance mode
如何回滚数据库,媒体,代码
转到Magento管理员根文件夹并显示用法:
php bin/magento setup:rollback --help
Usage:
setup:rollback [options]
Options:
-c, --code-file=CODE-FILE Basename of the code backup file in var/backups
-m, --media-file=MEDIA-FILE Basename of the media backup file in var/backups
-d, --db-file=DB-FILE Basename of the db backup file in var/backups
--magento-init-params=MAGENTO-INIT-PARAMS Add to any command to customize Magento initialization parameters
For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache"
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Help:
Rolls back Magento Application codebase, media and database
在此示例中,我将向您展示如何还原/回滚Magento数据库。回滚之前,请检查是否存在备份文件:
列出所有存在的备份文件
php bin/magento info:backups:list
输出:
Showing backup files in ./var/backups.
+---------------------------------+-------------+
| Backup Filename | Backup Type |
+---------------------------------+-------------+
| 1534245793_db.sql | db |
| 1534245893_filesystem_media.tgz | media |
+---------------------------------+-------------+
让我们回滚数据库
php bin/magento setup:rollback --db-file=1534245793_db.sql
它要求确认,键入:y
进行回滚过程。
输出:
Enabling maintenance mode
You are about to remove current code and/or database tables. Are you sure?[y/N]y
DB rollback is starting...
DB rollback filename: 1534245793_db.sql
DB rollback path: /var/www/html/sam/ce2252/var/backups/1534245793_db.sql
[SUCCESS]: DB rollback completed successfully.
Please set file permission of bin/magento to executable
Disabling maintenance mode
注意
所有备份文件都必须放在./var/backups/
文件夹中。