Backup and rollback the file system, media, and database
This command enables you to back up:
- The file system (excluding
varandpub/staticdirectories) - The
pub/mediadirectory - The database
Backups are stored in the var/backups directory and can be restored at any time using the magento setup:rollback command.
After backing up, you can rollback later.
Enable backups
The backup feature is disabled by default. To enable, enter the following CLI command:
bin/magento config:set system/backup/functionality_enabled 1
Backup functionality is deprecated as of 2.1.16, 2.2.7, and 2.3.0. We recommend investigating additional backup technologies and binary backup tools (such as Percona XtraBackup).
Set the open files limit
Rolling back to a previous backup can silently fail, resulting in incomplete data being written to the file system or database using the magento setup:rollback command.
Sometimes, a long query string causes the user鈥檚 allocated memory space to run out of memory because of too many recursive calls.
How to set open files ulimit
We recommend setting the open files for the file system user to a value of 65536 or more.
You can do this either on the command line or you can make it a permanent setting for the user by editing their shell script.
Before you continue, if you haven鈥檛 already done so, switch to the file system owner.
Command:
ulimit -s 65536
You can change this to a larger value if needed.
ulimit depends on the UNIX shell you use. The preceding setting should work with CentOS and Ubuntu with the Bash shell. However, for macOS, the correct setting is ulimit -S 65532. Consult a man page or operating system reference for more information.To optionally set the value in the user鈥檚 Bash shell:
-
If you haven鈥檛 already done so, switch to the file system owner.
-
Open
/home/<username>/.bashrcin a text editor. -
Add the following line:
code language-bash ulimit -s 65536 -
Save your changes to
.bashrcand exit the text editor.
php.ini file because it can result in incomplete rollbacks with no failure notice.Backing up
Command usage:
bin/magento setup:backup [--code] [--media] [--db]
The command performs the following tasks:
-
Puts the store in maintenance mode.
-
Executes one of the following command options.
table 0-row-3 1-row-3 2-row-3 3-row-3 Option Meaning Backup file name and location --codeBacks up the file system (excluding var and pub/static directories). var/backups/<timestamp>/_filesystem.tgz--mediaBack up the pub/media directory. var/backups/<timestamp>/_filesystem_media.tgz--dbBack up the database. var/backups/<timestamp>/_db.sql -
Takes the store out of maintenance mode.
For example, to back up the file system and database,
bin/magento setup:backup --code --db
Messages similar to the following display:
Enabling maintenance mode
Code backup is starting...
Code backup filename: 1434133011_filesystem.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Code backup path: /var/www/html/magento2/var/backups/1434133011_filesystem.tgz
[SUCCESS]: Code backup completed successfully.
DB backup is starting...
DB backup filename: 1434133011_db.sql
DB backup path: /var/www/html/magento2/var/backups/1434133011_db.sql
[SUCCESS]: DB backup completed successfully.
Disabling maintenance mode
Rollback
This section discusses how to roll back to a backup you made previously. You must know the file name of the backup file to restore.
To find the name of your backups, enter:
bin/magento info:backups:list
The first string in the backup file name is the timestamp.
To roll back to a previous backup, enter:
bin/magento setup:rollback [-c|--code-file="<name>"] [-m|--media-file="<name>"] [-d|--db-file="<name>"]
For example, to restore a media backup named 1440611839_filesystem_media.tgz, enter
bin/magento setup:rollback -m 1440611839_filesystem_media.tgz
Messages similar to the following display:
[SUCCESS]: Media rollback completed successfully.
Please set file permission of bin/magento to executable
Disabling maintenance mode