No matter how hard you try to prevent your store's data from a sudden disappearance, there is always a slight risk of different attacks or system failures. No matter how well-organized your store operation is, anything from installing Magento 2 extensions and deploying changes to updating Magento can cause some data to get lost.
To prevent this from happening you need backups. And luckily, you can back up Magento 2 in multiple ways.
Today, you'll learn about each of them in particular, so a copy of all the necessary data is created and can be easily restored.
Post Contents [hide]
Create Magento 2 Backup via Admin Panel
To create and schedule backups in Magento 2:
1. Go to Stores > Configuration > Advanced > System > Backup Settings.
2. Enable the backup by choosing Yes in the corresponding field.
3. Select Yes in the Enable Scheduled Backup field if you want to back up your data regularly.
4. Specify the Scheduled Backup Type. You've got 4 options here:
- Database
- Database and Media
- System
- System (excluding Media)
5. Set the Start Time for Magento backups.
6. Specify the Frequency of the backups, choosing Daily, Weekly, or Monthly in the corresponding field.
7. Make sure that your store is in the Maintenance Mode since this is what backups require.
Don't forget to press the Save Config button, once you finish.
Note: to make sure that the configuration works properly, go to System > Tools > Backups and check out your backups there.
Magento 2 Backup via Command Line
The backend is not the only place where you can create backups. You can as well back up Magento 2 using CLI. Use the following command to initiate the process:
bin/magento setup:backup [--code] [--media] [--db]
This command will put your store into maintenance mode, create the system files, media, and database backup, and turn off the maintenance mode afterwards.
You can then find the backups in the var/backups directory and restore them if required.
Backup Magento 2 Manually
Creating backups manually is not the most convenient way. But it still may come in handy sometimes.
To create a backup in Magento 2 manually:
1. Go to the /public_html directory in your hosting account.
2. Download the directory to your computer or save it to a different hosting folder.
3. Go to the cPanel and choose phpMyAdmin.
4. Choose your website's database.
5. Press the Export button and download it to your local computer as an SQL file.
6. Set the exporting method to Quick and press the Go button.
In case you don't want use SSH, try creating a backup via CLI.
You simply have to execute the following command to create a backup of the DB:
mysqldump -u db_user_name -p db_name > my_back_up_14_02_2023.sql
Then the system will ask you for the DB password. And finally, you'll need to compress the DB backup:
tar -zxcv my_back_up_14_02_2023.sql.tar.gz my_back_up_14_02_2023.sql
Pro tip: we strongly recommend you always create zip or tar archives of your files since it simplifies the file downloading. If you don't use archives, the data will take too much time to download.
There are indeed quite a lot of steps to take if you want to back up Magento. But the more methods you know, the better you are prepared for any unpredictable situation.
Choose the one you like the most and ease your concerns about losing any content or crucial data. But since system failure is not the only way to lose data, you also need to explore the best tips to improve Magento security to protect your store from any brute-force attacks or malicious actions.