How to Use Magento 2’s Built-in Backup and Rollback Features
How to Use Magento 2’s Built-in Backup and Rollback Features
Running an online store means dealing with unexpected issues—whether it's a failed update, a misconfigured setting, or even accidental data loss. That’s why having a solid backup and rollback strategy is crucial for any Magento 2 store owner. Luckily, Magento 2 comes with built-in tools to help you protect your store’s data and quickly recover when things go wrong.
In this guide, we’ll walk you through how to use Magento 2’s backup and rollback features step by step. By the end, you’ll know exactly how to secure your store and restore it with confidence.
Why Backups Matter in Magento 2
Before diving into the how-to, let’s quickly cover why backups are essential:
- Prevent Data Loss: Accidental deletions, corrupted databases, or failed updates can wipe out critical data.
- Quick Recovery: Instead of rebuilding your store from scratch, a backup lets you restore it in minutes.
- Safe Testing: Trying out new extensions or custom code? Backups let you revert if something breaks.
Types of Backups in Magento 2
Magento 2 supports three types of backups:
- Database Backup: Saves your store’s database (products, orders, customers, etc.).
- System Backup: Captures both the database and the file system (themes, extensions, media).
- Code & Media Backup: Backs up only the codebase (app, pub, var) and media files (images, videos).
Creating a Backup in Magento 2
Magento 2 allows you to create backups via the Admin Panel or the command line. Let’s explore both methods.
Method 1: Using the Admin Panel
- Log in to your Magento 2 Admin Panel.
- Go to System > Tools > Backups.
- Click Create Backup and select the type you need (Database, System, or Code & Media).
- Click OK to confirm. Magento will now generate the backup.
Note: Large stores may take a while to back up. Avoid interrupting the process.
Method 2: Using the Command Line
For more control, you can use the Magento CLI. Here’s how:
php bin/magento setup:backup --db
This creates a database backup. For a full system backup, run:
php bin/magento setup:backup --db --code --media
Backups are stored in var/backups/ by default.
Rolling Back a Backup in Magento 2
If something goes wrong, you can restore your store using a backup. Again, you have two options: Admin Panel or CLI.
Method 1: Using the Admin Panel
- Go to System > Tools > Backups.
- Find the backup you want to restore and click Rollback.
- Confirm the action—Magento will restore your store to that backup state.
Method 2: Using the Command Line
To restore via CLI, use:
php bin/magento setup:rollback --db-file "filename.sql"
Replace "filename.sql" with your actual backup file name.
Automating Backups
Manually creating backups works, but automation ensures you never miss one. Here’s how to set up a cron job for regular backups:
- Open your server’s crontab:
- Add a line to run backups daily (adjust the path to your Magento installation):
- Save and exit. Now, your store will back up every day at 2 AM.
crontab -e
0 2 * * * php /var/www/html/magento2/bin/magento setup:backup --db >/dev/null 2>&1
Best Practices for Magento 2 Backups
- Store Backups Offsite: Keep copies on cloud storage (AWS S3, Google Drive) in case of server failure.
- Test Restores: Periodically verify that backups work by restoring them in a staging environment.
- Monitor Disk Space: Backups consume storage—clean up old ones if needed.
When to Use Third-Party Backup Extensions
While Magento’s built-in backups work well, some stores need more advanced features like:
- Incremental backups (only backing up changes).
- One-click cloud storage integration.
- Scheduled, encrypted backups.
If these sound useful, check out extensions like Magefan Backup or Akeeba Backup for enhanced functionality.
Final Thoughts
Backups are your safety net—don’t wait until disaster strikes to set them up. Whether you use Magento’s built-in tools or an extension, regular backups ensure your store can recover quickly from any mishap.
Got questions? Drop them in the comments below! And if you’re looking for reliable Magento hosting with automated backups, check out Magefine’s hosting solutions.



