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.php and app/etc/config.php
  • Theme: Custom theme files (app/design/)

Creating a Database Backup

Via phpMyAdmin

  1. Log in to DirectAdmin
  2. Go to phpMyAdmin
  3. Select your Magento database
  4. Click on Export
  5. Choose Quick for standard export
  6. 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

You can find the database details (name, user, password) in app/etc/env.php, under 'db' => 'connection' => 'default'. For a shop that stays online, add --single-transaction so the dump is consistent without locking tables: mysqldump --single-transaction -u user -p database_name > backup.sql.

Via Magento CLI

Magento also has its own backup command. This feature is disabled by default, so enable it first:

bin/magento config:set system/backup/functionality_enabled 1
bin/magento setup:backup --db

Add --code and --media to include code and media files. Backups are stored in var/backups/. Adobe marks this feature as deprecated; for large shops, mysqldump is more reliable.

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

  1. Go to File Manager in DirectAdmin
  2. Navigate to your Magento installation
  3. Select the important folders:
    • pub/media/ (images)
    • app/code/ (custom modules)
    • app/design/ (themes)
    • app/etc/ (configuration)
  4. Click on Compress to create a ZIP
  5. 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

  1. Connect with FTP client (FileZilla)
  2. Download the entire Magento folder
  3. Or download only critical folders

Magento Backup

Magento has built-in backup functionality:

Backup via Admin

  1. Go to System > Tools > Backups (disabled by default; enable it under Stores > Configuration > Advanced > System > Backup Settings; Adobe marks this feature as deprecated)
  2. Choose backup type:
    • System Backup: Files only
    • Database Backup: Database only
    • Database and Media Backup: Both (recommended)
  3. Click on the desired backup button
  4. Wait until the backup is complete

Note: This method may timeout for large shops. Use the command line instead.

Backup via CLI

For a backup via the command line, use mysqldump or bin/magento setup:backup, as described above under creating a database backup. The support:backup:db and support:backup:code commands you may come across in some guides are part of the Adobe Commerce Support Tools and do not exist in Magento Open Source.

Restoring Backups

Database Restore via phpMyAdmin

  1. Go to phpMyAdmin
  2. Select your database (or create a new one)
  3. Click on Import
  4. Select your SQL backup file
  5. 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

  1. Upload the backup to the server (via FTP or File Manager)
  2. Extract the archive in the correct location
  3. 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

# Update database and modules
bin/magento setup:upgrade

# 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

  1. Daily database backups: Automate with cronjobs
  2. Weekly full backups: Including files
  3. Test your backups: Restore periodically on test environment
  4. External storage: Keep copies outside the server
  5. Document: Note where backups are stored
  6. Encryption: Encrypt sensitive backups
  7. Retention: Keep at least 30 days of history

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.

Looking for web hosting? See what we offer.