virtualMachinemagento

Create and restore application backups

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

Magento 2.3 and later no longer include built-in backup functionality. Therefore, backup (and restore) operations must be performed manually using external tools.

Backup

The steps below explain the process of backing up the Magento database and media files. They do not cover the process of backing up the Magento application itself or any installed extensions. Extensions, if any, should be reinstalled using the Magento control panel when the backup is restored.

The steps below assume that:

  • You have the administrator password for the Magento control panel.
  • You have the root password for the database server.
  • You are able to log in to the Magento server console.

To obtain a list of installed extensions, follow these steps:

  • Log in to the Magento control panel as an administrator.

  • Navigate to the “System -> Web Setup Wizard -> Extension manager” page.

  • Note the list of installed plugins, together with their version numbers.

    Magento installed extension list

Then, follow the steps below to back up the Magento database and media files:

  • Put Magento into maintenance mode:

      $ sudo magento-cli maintenance:enable
    
  • Backup the bitnami_magento database as described in the Create and restore MySQL/MariaDB backups page.

  • Execute the commands below to back up the Magento media directory, depending on your installation type:

    • Approach A (Bitnami installations using system packages):

        $ sudo tar -czv -C /opt/bitnami/pub -f /tmp/magento_media.tgz media
      
    • Approach B (Self-contained Bitnami installations):

        $ sudo tar -czv -C /opt/bitnami/apps/htdocs/pub -f /tmp/magento_media.tgz media
      
  • Disable maintenance mode:

      $ sudo magento-cli maintenance:disable
    

At this point, two backup files have been created: backup.sql for the database backup, and /tmp/magento_media.tgz for Magento media files.

You should now download or transfer these files to a safe location. At the same time, make a note of the administrator password, as this will be needed at the time of restoring the backup.

Restore

The steps below assume that:

  • You have installed the Bitnami Magento stack.
  • You have the administrator password for the Magento control panel.
  • You have the root password for the database server.
  • You are able to log in to the Magento server console.

Before proceeding with the steps below, if your original installation included additional extensions, navigate to the Magento control panel and reinstall any extensions needed using the extension manager and the list made at backup time.

To restore a backup, follow these steps:

  • Transfer the backup files to the Magento server.

  • Stop all services:

      $ sudo /opt/bitnami/ctlscript.sh stop
    
  • Restore the bitnami_magento database backup as described in the Create and restore MySQL/MariaDB backups page.

IMPORTANT: After performing this step, the Magento administrator password will be reset to the value in the backup file.

  • Uncompress and restore the media backup. Depending on your installatin type, execute the commands below:

    • Approach A (Bitnami installations using system packages):

        $ sudo tar -xzvf /tmp/media.tgz -C /opt/bitnami/magento/pub
      
    • Approach B (Self-contained Bitnami installations):

        $ sudo tar -xzvf /tmp/media.tgz -C /opt/bitnami/apps/magento/htdocs/pub
      
  • Restart all services:

      $ sudo /opt/bitnami/ctlscript.sh start
    
  • Run the Magento indexer to update Magento with the new data:

      $ sudo magento-cli indexer:reindex
    

Your Magento database and media files should now be restored.

NOTE: Remember that you will now only be able to log in to the Magento control panel using the previous administrator password. You should log in and change this password as soon as possible.

Last modification June 16, 2021