Managing Magento 2 backup via the command line

Every production environment needs a proper backup plan. By default, Magento 2 has a complete set of options to create and roll back backups.

When creating a backup, we can use one of the following options:

Option

Meaning

Backup file name

--code

This creates a backup from the filesystem (excluding /var and /pub/static

var/backups/<timestamp>_filesystem.tgz

--media

This creates a backup from the /media directory

var/backups/<timestamp>_filesystem_media.tgz

-db

This creates a backup from the current database

var/backups/<timestamp>_db.gz

Tip

Besides the Magento backup options, it is always advisable to use an alternative backup solution connected to a backup storage.

Getting ready

When creating ...

Get Magento 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.