Ora

How to create backup in Magento?

Published in Magento Backup 7 mins read

Creating a robust backup for your Magento store is a critical task that safeguards your e-commerce business against data loss, system failures, and security breaches. A complete Magento backup primarily involves securing both its file system and its database.

Understanding Magento Backups: Files and Database

To ensure a full recovery of your Magento store, you must back up two distinct components:

  • Magento Files: This includes the entire directory structure of your Magento installation. It encompasses core Magento files, themes, extensions, custom code, uploaded media (images, videos), configuration files, and more. Losing these files means losing your storefront's appearance, functionality, and media assets.
  • Magento Database: This is where all dynamic and critical store data resides. It contains product information, customer accounts, order history, store configurations, categories, prices, shipping methods, and all transactional data. Without a database backup, your storefront would appear empty, even if the files are intact.

Method 1: Manual Backup via Hosting Control Panel (Recommended for Full Control)

This method provides granular control and is highly recommended as a primary backup strategy, especially for shared or VPS hosting environments. It directly leverages tools found in most web hosting control panels like cPanel.

Step-by-Step File System Backup

Backing up your Magento files involves copying the entire installation directory.

Accessing Your Hosting Account Files

  1. Go to the /public_html directory in your hosting account. You can typically do this through your hosting provider's File Manager within cPanel or by using an FTP/SFTP client (like FileZilla). The public_html directory is often the root directory for your primary domain, but your Magento installation might be in a subdomain's directory or a subfolder within public_html.
  2. Locate your Magento installation. Identify the main folder containing your Magento files (e.g., app, bin, pub, var directories).

Downloading Your Magento Files

  1. Download the directory to your computer or save it to a different hosting folder. For easier and faster download, it's highly recommended to first compress your entire Magento installation directory (e.g., public_html or your specific Magento root folder) into a .zip or .tar.gz archive. Most File Managers offer a "Compress" or "Archive" option.
  2. Once compressed, download the archive file (e.g., magento_files_backup_YYYY-MM-DD.zip) to your local computer. For very large sites, using an FTP/SFTP client is more reliable than a web-based file manager.

Step-by-Step Database Backup

The database backup process involves exporting your store's dynamic data into an SQL file.

Navigating to phpMyAdmin

  1. Go to the cPanel and choose phpMyAdmin. phpMyAdmin is a web-based tool for managing MySQL databases, allowing you to easily browse, edit, and export database contents.

Selecting Your Magento Database

  1. Choose your website's database. In the left sidebar of phpMyAdmin, you will see a list of databases. You need to identify the specific database associated with your Magento installation. This information can usually be found in your Magento app/etc/env.php file (look for db > connection > default > dbname).

Exporting the Database

  1. Press the Export button located in the top menu bar of phpMyAdmin.
  2. Select the Export Method:
    • Quick: This is suitable for most users and will export the entire database with minimal options.
    • Custom: This option provides more control, allowing you to select specific tables, compression methods, and other advanced settings. For a full backup, ensure all tables are selected.
  3. Choose the Format: Ensure the format is set to SQL.
  4. Download it to your local computer as an SQL file. Click "Go" (or "Export" depending on your phpMyAdmin version) to start the download. The file will typically be named your_database_name.sql (or your_database_name.sql.gz if compressed).

Method 2: Magento's Built-in Backup Feature (Use with Caution for Magento 2)

Magento offers a built-in backup functionality, though its effectiveness varies significantly between versions and is often not recommended for Magento 2 production environments due to performance and reliability issues.

For Magento 1.x Stores

Magento 1 has a more robust and commonly used built-in backup system:

  1. Navigate to System > Tools > Backups.
  2. You'll find options for:
    • System Backup: Backs up both the database and media files.
    • Database Backup: Backs up only the database.
    • Media Backup: Backs up only the media folder.
  3. Select the desired backup type, provide a name, and click the "Backup" button. You may also have an option to put your store into maintenance mode during the backup.

For Magento 2.x Stores (Use with Caution)

While Magento 2 technically has a backup feature, it is generally not recommended for production sites, especially large ones. It can consume significant server resources, potentially leading to timeouts or incomplete backups. Server-level or manual backups are preferred.

If you choose to use it (e.g., for development environments):

  1. Go to System > Tools > Backups (or System > Data Transfer > Backups in some older versions).
  2. You'll see options like "System Backup" and "Database Backup."
  3. Follow the prompts to initiate the backup. Be aware that the process can be slow and may require increasing PHP execution limits for large stores.

Method 3: Utilizing Your Hosting Provider's Backup Services

Many web hosting providers offer automated backup services as part of their plans. These are convenient and often run daily or weekly without your intervention.

  • Check your hosting plan: Verify if your provider includes automated backups and understand their retention policy (how long backups are kept).
  • How to restore: Familiarize yourself with how to request a restore from your host, as this process varies.

While convenient, relying solely on your host's backups is not advisable. Always maintain your own independent backups for maximum security.

Method 4: Third-Party Backup Extensions

For those looking for more automation and advanced features, numerous third-party Magento extensions are available to streamline the backup process.

  • Features: These extensions often provide scheduled backups, cloud storage integration (AWS S3, Dropbox), incremental backups, and easier restoration interfaces.
  • Selection: Research reputable extensions compatible with your Magento version (e.g., Amasty Backup, Aheadworks or others found on the Magento Marketplace). Always check reviews and support.

Best Practices for Magento Backups

Implementing a robust backup strategy goes beyond just creating the files; it includes how you manage them.

  • Regularity: Schedule backups according to your store's activity.
    • Daily: For highly active stores with frequent orders and content updates.
    • Weekly/Bi-weekly: For less active stores.
    • After every major change: Always perform a backup before applying updates, installing new extensions, or making significant configuration changes.
  • Storage Location: Store backups off-site and in multiple locations. This could include cloud storage (Google Drive, Amazon S3), external hard drives, or a different server. Never keep your only copy of a backup on the same server as your live Magento store.
  • Testing: Periodically test your backups by attempting to restore them to a staging or local environment. This verifies that your backups are valid and can be successfully used for recovery.
  • Versioning: Keep multiple versions of your backups (e.g., daily for 7 days, weekly for 4 weeks, monthly for 3 months). This allows you to roll back to different points in time if an issue isn't immediately detected.
  • Security: Ensure your backup files are stored securely with appropriate access controls and encryption, especially if they contain sensitive customer data.

Troubleshooting Common Backup Issues

Issue Description Solution
Large File Size Your Magento directory or database is too large to download or export easily. For files, compress the directory into a .zip or .tar.gz archive before downloading. For very large databases, phpMyAdmin may time out. Consider using command-line tools like mysqldump via SSH for more robust database exports, or contact your hosting provider.
Permissions Errors related to file or directory permissions during backup or restoration. Ensure that file and directory permissions are correctly set for your Magento installation. Typically, directories are 755 and files are 644.
Server Load Backup process causes high server load, slowing down your store. Schedule backups during off-peak hours. Use server-level backups if available. For Magento 2, avoid the built-in backup feature for large production sites.
Incomplete Backup Not all files or database tables are included in the backup. Verify the scope of your backup. For manual methods, double-check that you're archiving the correct root directory and selecting the entire database in phpMyAdmin. For built-in/third-party tools, review their configuration settings.

In conclusion, establishing a robust and multi-faceted backup strategy is non-negotiable for any Magento store owner. Combining manual methods with automated solutions from your host or third-party extensions provides the most secure foundation for your e-commerce operations.