Cómo usar las funciones de copia de seguridad y restauración integradas de Magento 2
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.
En esta guía,’ll walk you through cómo use Magento 2’s backup and rollback features paso a paso. By the end, you’ll know exactly cómo secure your store and restore it with confidence.
Why Backups Matter in Magento 2
Antes de 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 desde cero, a backup le permite 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 le permite create backups via the Panel de administración or the línea de comandos. Let’s explore both methods.
Method 1: Using the Panel de administración
- Log in to your Magento 2 Panel de administración.
- 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/ por defecto.
Rolling Back a Backup in Magento 2
If something goes wrong, you can restore your store using a backup. Again, you have two options: Panel de administración or CLI.
Method 1: Using the Panel de administración
- 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 cómo set up a tarea cron 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. Ahora, 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
Mejores prácticas 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
Mientras 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.
Reflexiones finales
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.