Creating and Restoring Magento Backups: A Guide
Regular backups are essential for every Magento webshop. In this guide, you will learn how to create and restore complete backups.
What should you backup?
A complete Magento backup consists of:
- Database: All products, orders, customers, configuration
- Media: Images and uploads (
pub/media/) - Code: Custom code and extensions (
app/code/) - Configuration:
app/etc/env.phpandapp/etc/config.php - Theme: Custom theme files (
app/design/)
Creating a Database Backup
Via phpMyAdmin
- Log in to DirectAdmin
- Go to phpMyAdmin
- Select your Magento database
- Click on Export
- Choose Quick for standard export
- Click on Go and download the SQL file
Via Command Line
# Navigate to Magento root
cd /path/to/magento
# Create database backup with timestamp
mysqldump -u user -p database_name > backup_$(date +%Y%m%d).sql
# Or with Magento CLI
bin/magento db:dump
The CLI method saves the backup in var/backups/.
Compressed Backup
For large databases:
mysqldump -u user -p database_name | gzip > backup_$(date +%Y%m%d).sql.gz
Creating a Files Backup
Via File Manager
- Go to File Manager in DirectAdmin
- Navigate to your Magento installation
- Select the important folders:
pub/media/(images)app/code/(custom modules)app/design/(themes)app/etc/(configuration)
- Click on Compress to create a ZIP
- Download the ZIP
Via Command Line
# Navigate to above Magento root
cd /path/to/
# Create a full backup
tar -czvf magento_backup_$(date +%Y%m%d).tar.gz magento/
# Or only specific folders
tar -czvf media_backup_$(date +%Y%m%d).tar.gz magento/pub/media/
Via FTP
- Connect with FTP client (FileZilla)
- Download the entire Magento folder
- Or download only critical folders
Magento Support Backup
Magento has built-in backup functionality:
Backup via Admin
- Go to System > Backup
- Choose backup type:
- System Backup: Files only
- Database Backup: Database only
- Database and Media Backup: Both (recommended)
- Click on the desired backup button
- Wait until the backup is complete
Note: This method may timeout for large shops. Use the command line instead.
Backup via CLI
# Database only
bin/magento support:backup:db
# Database and code
bin/magento support:backup:code --with-database
# All support backup options
bin/magento support:backup:code --include-media --with-database
Restoring Backups
Database Restore via phpMyAdmin
- Go to phpMyAdmin
- Select your database (or create a new one)
- Click on Import
- Select your SQL backup file
- Click on Go
Database Restore via Command Line
# Decompress if necessary
gunzip backup.sql.gz
# Import database
mysql -u user -p database_name < backup.sql
Files Restore
- Upload the backup to the server (via FTP or File Manager)
- Extract the archive in the correct location
- Check file permissions
# Extracting
tar -xzvf magento_backup.tar.gz
# Restore permissions
find var generated pub/static pub/media -type d -exec chmod 755 {} \;
find var generated pub/static pub/media -type f -exec chmod 644 {} \;
Post-Restore Actions
# Clear cache
bin/magento cache:clean
bin/magento cache:flush
# Rebuild indexes
bin/magento indexer:reindex
# Compile DI
bin/magento setup:di:compile
# Deploy static content
bin/magento setup:static-content:deploy nl_NL
Automated Backups
Via Cronjob
Set up a cronjob for automated backups:
# Daily database backup at 3:00
0 3 * * * /usr/bin/mysqldump -u user -p'pass' database | gzip > /backups/db_$(date +\%Y\%m\%d).sql.gz
# Weekly full backup on Sunday at 4:00
0 4* * 0 tar -czvf /backups/full_$(date +\%Y\%m\%d).tar.gz /path/to/magento
Backup Rotation
Automatically delete old backups:
# Delete backups older than 30 days
find /backups/ -name*.gz" -mtime +30 -delete
External Backup Storage
Store backups outside the server:
- Cloud storage (AWS S3, Google Cloud, Dropbox)
- External FTP server
- Local download to computer
Best Practices
- Daily database backups: Automate with cronjobs
- Weekly full backups: Including files
- Test your backups: Restore periodically on test environment
- External storage: Keep copies outside the server
- Document: Note where backups are stored
- Encryption: Encrypt sensitive backups
- Retention: Keep at least 30 days of history
Related Articles
- Installing Magento via Installatron
- Troubleshooting Magento Issues
- Setting Up Cronjobs in DirectAdmin
Need Help?
We are here for you! Are you facing any issues or do you have questions? Our support team is happy to assist you personally. Send us a message via the ticket system - we usually respond within a few hours and are eager to help.
Was dit artikel nuttig?
0 van 0 vonden dit nuttig