Magento 2 Backup Steps using SSH and FTP
Magento 2 backup creates a copy of your website's data, which can be used in emergencies or server crashes. Backups serve the purpose of restoring your code and data to your store. It is essential to regularly back up your Magento 2 store to prevent any data loss. This tutorial will explore backing up Magento using SSH and FTP.
Key Takeaways
-
Gain insight into different types of Magento backups.
-
Learn the process of backing up Magento using SSH.
-
Discover the steps to back up Magento via FTP.
-
Equip yourself with strategies to prevent data loss in Magento 2 via FAQs.
Types of Magento Backups
-
System backup: This backup method guarantees the preservation of all content, including the Magento 2 file system, media folder, and database.
-
Database and media backup: It will create a backup of your media folder and Magento 2 database for safekeeping.
-
Database backup: This backup is specifically used for saving the Magento 2 database.
How to Create Magento Backup Via SSH
To make a Magento backup, we must be logged in through SSH using the user account.
Once logged in, navigate to the document root of your Magento store (Magento 2 store installation directory), where our Magento 2 installation is located.
You can quickly and easily back up our Magento 2 store using the "Magento setup:backup" command. By applying flags to the command, you can specify the type of backup you want to create.
magentotest@newvps public_html]$ magento setup:backup --code --media --db
Enabling maintenance mode
Code backup is starting...
Code backup filename: 1648215256_filesystem_code.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Code backup path: /home2/magentotest/public_html/var/backups/1648215256_filesystem_code.tgz
[SUCCESS]: Code backup completed successfully.
Media backup is starting...
Media backup filename: 1648215256_filesystem_media.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Media backup path: /home2/magentotest/public_html/var/backups/1648215256_filesystem_media.tgz
[SUCCESS]: Media backup completed successfully.
DB backup is starting...
DB backup filename: 1648215256_db.sql
DB backup path: /home2/magentotest/public_html/var/backups/1648215256_db.sql
[SUCCESS]: DB backup completed successfully.
Disabling maintenance mode
When you use the backup command, it puts the store in maintenance mode. This means that the front page of your store will show a message saying that the website is unavailable.
After the backup, the store will return to normal and ready to use. All the backups you have created can be found in the var/backups directory.
How to Create Magento Backup Via FTP
To back up your Magento store, you can use FTP to transfer the data to an external server. key steps you need to follow are:
- You can connect to your server with an FTP client like FileZilla or WinSCP.
- Go to the root directory of Magento. For instance:
/home/cloudpanel/htdocs/www.domain.com
- Now, download the root directory onto your local system and compress it.
- Log in to your MGT Control Panel.
- Go to the Magento Database by following the path: Databases > Magento Database.
- Open the database by accessing PHPMyAdmin.
- To export, choose the database and click on the export option.
- To quickly export the database, select the "Quick exporting method" and choose the SQL format. Then, click the "Go" button to initiate the download.
FAQs
1. What is the difference between automatic and manual Magento 2 backups?
Automatic backups are scheduled through a cron job to occur at regular intervals without any input from the user. In contrast, manual backups require the user to initiate the process from the admin panel or command line.
2. How can I restore files from my Magento 2 backup?
Restoring files from a Magento 2 backup involves accessing the stored backup and decompressing the files. After that, you can use the rollback command from the command line or the admin panel to restore your store's data.
3. What backup types and tools are available for Magento 2 stores?
Magento 2 offers three types of backups: System Backup, Database and Media Backup, and Database Backup. You can use command line tools or the built-in backup and restore functionality in the admin panel, depending on your experience and preference.
4. How can I ensure my Magento 2 backups are secure?
Implementing security measures, such as compression and encryption for your backup files and offsite storage for your backups, can help keep your store's information safe. Also, it's advisable to name backups distinctively for easy identification and efficient rollback if any events disrupt your business service. Choosing the right Magento hosting providers also ensures that backups are secure and easily accessible.
5. What methods and tools are available in Magento 2 to back up product categories and individual products?
Magento 2 offers several methods to back up product categories and individual products. This can be done manually through the admin panel or automatically using CLI commands. A store owner can navigate to the 'Backup settings' section in the admin panel and select the 'System Backup' option, which includes all site data, categories, and products. Note that the size of your backup file will increase with the number of products and categories.
6. How frequently should Magento 2 backups be performed, and can this be automated?
The frequency of Magento 2 backups depends on the store size, the number of daily updates, and the resources available. However, many experts in the Magento community recommend a daily backup. This can be automated by setting a cron job through the CLI or by configuring the 'Backup Settings' in the 'Configuration' menu of the admin panel. Select 'Yes' for the 'Enable Scheduled Backup' and 'Save Config' options to automate the process.
7. How should the backup files of Magento 2 be named and stored for easy identification and access?
Backup files should be named distinctively, usually including the type of backup (code file, db-file, media file), the date, and the Magento version. This makes it easier for the store or computer system owner to identify and manage the files. It's also recommended to store the backup files offsite for better security. Services like Google Cloud Storage can be utilized for this purpose.
8. How can I ensure the security of my Magento 2 backup files and protect my customers' data?
Ensuring the security of Magento 2 backups is of paramount importance. One way to protect backup files is by using password encryption, which can be applied using cPanel or CLI. Another method is storing backups offsite, away from the main server. Also, consider extensions offering additional security features, such as Two-Factor Authentication or IP Whitelisting. Always regularly update these extensions and your Magento application for the latest security updates.
Summary
Magento 2 backup helps prevent crashes, hacks, and other data loss mishaps. You can create backups manually, using SSH or via FTP. Remember to regularly back up your store to prevent losses and ensure your data is secure. Opting for the right Magento-managed hosting also facilitates efficient backup and recovery operations.