Bash Script: Backup Magento2 Code + Database
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Bash Script: Backup Magento2 Code + Database

This utility script helps you to backup Magento2 code and database.
You can either run the command manually or can automate it via cronjob.


You can simply download the script file and give the executable permission.

curl -0 -o
chmod +x

To make it system wide command

sudo mv /usr/local/bin/


To display help

./ --help

To backup database only

./ --type=db --src-dir=/path/to/magento2/root --dest-dir=/path/to/destination

To backup code only

./ --type=code --skip-media=1 --src-dir=/path/to/magento2/root --dest-dir=/path/to/destination

To backup code + database

./ --type=all --skip-media=1 --src-dir=/path/to/magento2/root --dest-dir=/path/to/destination

To schedule backup via Cron

If you want to schedule via Cron, just add the following line in your Crontab entry crontab -e

0 0 * * * /path/to/ --type=all --skip-media=1 --src-dir=/path/to/magento2/root --dest-dir=/path/to/destination > /dev/null 2>&1

0 0 * * * expression means the command will run run at every midnight.


Mage2Backup Help

  1. Screentshot - Mage2Backup Help


  • S3 support
  • Google Drive support
  • Option to exclude log tables