Regular maintenance is necessary while running a Magento 2 store on Adobe Commerce Cloud (previously known as Magento Commerce Cloud). Database backups are among the most important maintenance activities. A database dump is a must when moving environments, backing up data, or getting ready for changes. This blog article will guide you through taking an Adobe Commerce Cloud database dump.
Get a Database Dump: Why Do It?
Let’s quickly go over the reasons why you might need to perform a database dump before we get into the steps:
- Backup and restore: Guard your data from unintentional deletion or corruption.
- Migrate your database between environments (from staging to production) using environment migration.
- Development and Testing: Benefit from using actual data in your surroundings for development and testing, enhancing the practicality of your work.
In order to proceed, your role is significant. You’ll need:
Adobe Commerce Cloud Access: Verify that you possess the required authorizations to enter and oversee your Adobe Commerce Cloud project.
Magento Cloud CLI: The Magento Cloud CLI needs to be installed and set up on your local computer.
Magento 2: How to Take a Database Dump in Adobe Commerce Cloud
Option 1: db-dump (ece-tools; recommended)
You can use the ECE-Tools command to dump your database.
vendor/bin/ece-tools db-dump
According to the official document, it is the safest command to use. This command will ask for several permissions before starting to dump the database. It will put your store in maintenance mode to avoid any database operation issues. Also, it will stop CRONS and terminate running CRON jobs.
Option 2: mysqldump
mysqldump -h <host> -u <username> -p <password> --single-transaction <db_name> | gzip > /tmp/<dump_name>.sql.gz
I am attaching a screenshot of the warning from the official portal of Adobe Commerce Cloud. Please take care of it before using the mysqldump command.
It is necessary to remove the database backup made in \tmp using the mysqldump command. It shouldn’t use up \tmp storage space (which could cause issues).
You could use the MAGENTO_CLOUD_RELATIONSHIPS environment variable to retrieve your database credentials, which include host, username, and password:
echo $MAGENTO_CLOUD_RELATIONSHIPS |base64 --d |json_pp
Option 3: magento-cloud db:dump
This command retrieves and stores the database locally in the current environment. You might pass the –gzip flag to lower the file size. You can also specify the –environment flag to dump a particular environment.
To use this command, you must install Adobe Commerce Cloud CLI on your local system.
magento-cloud db:dump -e staging -f db-dump.sql
That’s it. Thank you for reading our blog. Please subscribe and share with your connections.
Note: Please verify the code of this blog and the relevant git repository before using it in production.
🙂 HAPPY CODING 🙂