nativeInstallermagento

Create and restore application backups

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

Magento 2.3 and later no longer includes built-in backup functionality. Therefore, backup (and restore) operations must be performed manually using external tools. This guide uses Percona XtraBackup, an open source backup utility for MySQL, to back up and restore the Magento database.

NOTE: The steps below are only applicable for Linux native installers.

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:

  • Install Percona XtraBackup on the Magento server using the official installation instructions for your operating system.
  • Put Magento into maintenance mode:

    $ cd installdir/apps/htdocs/bin
    $ sudo ./magento-cli maintenance:enable
    
  • Execute the commands below to back up the database using Percona XtraBackup. Replace the DB-ADMIN-PASSWORD password with the password for the database root user.

    $ cd /tmp
    $ mkdir mybackup        
    $ sudo xtrabackup --backup  --target-dir=mybackup --socket=installdir/mysql/tmp/mysql.sock --user=root --databases=bitnami_magento --password=DB-ADMIN-PASSWORD 
    $ sudo chown -R bitnami.bitnami mybackup
    $ xtrabackup --prepare --target-dir=mybackup/
    $ cd mybackup
    $ tar -czvf db.tgz *
    

IMPORTANT: When using the chown command, maintain the original ownership for the files and folders. For example, if you originally installed the stack as the root user on Linux, make sure that the backup directory is owned by root as well.

  • Execute the commands below to back up the Magento media directory:

    $ cd installdir/apps/htdocs/pub
    $ sudo tar -czvf /tmp/mybackup/media.tgz media
    
  • Disable maintenance mode:

    $ cd installdir/apps/htdocs/bin
    $ sudo ./magento-cli maintenance:disable
    

At this point, the /tmp/mybackup directory contains two backup files, db.tgz for the Magento database and 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 installdir/ctlscript.sh stop
    
  • Create a directory for the backup files:

    $ cd /tmp
    $ mkdir mybackup        
    $ mv db.tgz media.tgz mybackup
    
  • Uncompress and restore the database backup:

    $ cd mybackup
    $ tar -xzvf db.tgz
    $ sudo rsync -avrP --chown=mysql:mysql . installdir/mysql/data/
    

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:

    $ cd installdir/apps/magento/htdocs/pub
    $ sudo tar -xzvf /tmp/mybackup/media.tgz
    $ sudo chown -R daemon.daemon media/
    

IMPORTANT: When restoring data, remember to maintain the original ownership for the files and folders. For example, if you originally installed the stack as the root user on Linux, make sure that the restored files are owned by root as well.

  • Restart all services:

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

    $ cd installdir/apps/magento/htdocs/bin
    $ 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 October 17, 2019