Question

How to manually backup magento files using CLI SSH

Hello, can you please advice a tutos how to backup magento files from the installed droplet on our server digital ocean? Thanks


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
April 22, 2024

Heya, @zakchapman

Magento’s built-in backup functionality will come handy in this situation. You can then use rsinc or scp to transfer the backup to a remote server.

The run the backup, execute the following command:

bin/magento setup:backup --code --media --db

This command will create a backup of your Magento instance including code, media files, and the database.

Once the backup is created, you can use rsync to transfer the backup to another location. For example, if you want to transfer it to a remote server, you can use a command like this:

rsync -avz /path/to/your/magento/var/backups/ user@remote_server:/path/to/destination/

Replace /path/to/your/magento/var/backups/ with the actual path to your Magento backups directory, user with the username on the remote server, remote_server with the IP address or hostname of the remote server, and /path/to/destination/ with the destination directory on the remote server where you want to transfer the backup.

After the transfer is complete, verify that the backup files are present in the destination directory on the remote server.

Hope that this helps!

KFSys
Site Moderator
Site Moderator badge
April 21, 2024

Backing up your Magento files from a droplet on DigitalOcean involves a few steps to ensure you safely store your data. Here’s a basic tutorial on how to do this:

Prerequisites

  1. Access to your DigitalOcean Droplet: You need to have SSH access to your droplet.
  2. Sufficient Storage: Ensure your droplet or your backup destination has enough space to store the backup.

Steps to Backup Magento Files

Step 1: Connect to Your Droplet

Open a terminal on your local machine and use the following command to connect to your DigitalOcean droplet via SSH. Replace your_username with your actual username and your_droplet_ip with your droplet’s IP address.

ssh your_username@your_droplet_ip

Step 2: Navigate to the Magento Installation Directory

Once connected, you need to navigate to the directory where Magento is installed. This is typically under /var/www/html or a similar directory. You can change to this directory using:

cd /path/to/magento

Replace /path/to/magento with the actual path where Magento is installed on your droplet.

Step 3: Create a Backup of Magento Files

You can use the tar command to create a compressed archive of your Magento files. This makes it easier to transfer and store.

tar -czvf magento-backup-$(date +%Y%m%d).tar.gz .

This command will create a compressed tar archive of all files in the current directory (which should be your Magento root directory) and name it with the current date for easy reference.

Step 4: Move the Backup to a Safe Location

You can move the backup file to a safe location such as another server, an external storage device, or a cloud storage service. For example, to copy the backup to a remote server, you can use the scp command:

scp magento-backup-$(date +%Y%m%d).tar.gz username@backupserver:/path/to/backup/

Replace username@backupserver:/path/to/backup/ with the appropriate username, server, and path where you want to store the backup.

Step 5: Verify the Backup

It’s important to check that your backup file contains all the necessary files. You can list the contents of the tar file using:

tar -tzf magento-backup-$(date +%Y%m%d).tar.gz

Additional Tips

  • Automate Backups: Consider setting up a cron job to automate this process.
  • Database Backup: Don’t forget to also back up your Magento database. Use mysqldump or a similar tool to export your database to a file.
  • Security: Ensure your backup files are stored securely and are only accessible to authorized users.

This guide should help you create a backup of your Magento files on a DigitalOcean droplet. Remember to test your backup by trying to restore it to a different server to ensure it works correctly.

Bobby Iliev
Site Moderator
Site Moderator badge
April 20, 2024

Hi there,

As Magento has quite a few files, I could suggest using the rsync command.

You can follow the steps on how to do that here:

https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories

But in general, what you would do is:

  1. SSH into your server: First, you need to access your server where Magento is installed. You can do this by running:

    ssh username@your_server_ip
    

    Replace username with your server’s username and your_server_ip with the IP address of your server.

  2. Navigate to the Magento root directory: This is where your Magento files are stored. It’s typically located in a directory like /var/www/html/magento. Change to this directory:

    cd /var/www/html/magento
    
  3. Create a backup directory: If you don’t already have a backup directory, you can create one either locally on the same server or on a remote server. Here’s how to create a directory on the same server:

    mkdir -p /path/to/your/backup_directory
    
  4. Use rsync to copy files: You can now use rsync to synchronize the files from your Magento directory to the backup directory. If backing up on the same server, you could use:

    rsync -avz --progress /var/www/html/magento/ /path/to/your/backup_directory/
    

    The options -avz tell rsync to operate in archive mode, ensure verbosity, and compress file data during the transfer, respectively. The --progress option displays detailed progress of rsync execution.

  5. Verifying the backup: After the rsync process completes, ensure that all files are correctly copied to the backup directory. You can check the contents using:

    ls -l /path/to/your/backup_directory/
    

Let me know if you have any questions!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel