Question

How to backup site to my computer

Posted April 27, 2021 201 views
BackupsDatabases

I don’t have any coding knowledge. Developer set up my Magento site here. I would like to back up database and all coding files to my computer. I would like to have back up in case something happens and database or coding files are lost on hosting.

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.

×
Submit an Answer
2 answers

Hi @rajb,

Before letting you know how you can backup your website locally, I’ll recommend using the DigitalOcean backup solution, it’s just for such cases. There are two types:

  • Backups
  • Snapshots

Backups:
Backups are automatically-created disk images of Droplets. Enabling backups for Droplets enables system-level backups at weekly intervals, which provides a way to revert to an older state or create new Droplets.

You can read more about them here :

https://docs.digitalocean.com/products/images/backups/

Snapshots:

Snapshots are on-demand disk images of DigitalOcean Droplets and volumes saved to your account. Use them to create new Droplets and volumes with the same contents.

You can read more about them here:

https://docs.digitalocean.com/products/images/snapshots/

In your case, maybe the Snapshots is the better option.

Anyway, to download your website over locally, you’ll need to have SSH connection. Maybe if you are on Windows, you can use Putty.

To transfer a file from a remote machine to your local machine, run the following command:

scp -r username@10.10.0.1:/remote/directory/ /local/directory

you need to change the username and the IP address. To scp to a different port use:

scp -P 2222 -r username@10.10.0.1:/remote/directory/ /local/directory

Like scp, rsync is used to copy files either to or from a remote host, or locally on the current host.

rsync -avz user@10.10.0.1:/remote/directory/new_image.png /local/directory

To use rsync on different port:

rsync -avz -e "ssh -p $portNumber" user@10.10.0.1:/path/to/files/ /local/path/

Now, you need to find where your Magento is stored as well and copy the files from there to your local machine.

  • Regarding your database, you’ll need to find the configuration file. You can see it at /<Magento Install Dir>/app/etc/env.php.

    Opening the file, you’ll see the values for:

    • ‘host’
    • 'dbname’
    • 'dbusername’
    • 'password’

    You’ll need to copy them so that you have them and ready to copy. Once you know the details, close the env.php file and type in the following command to dump your database. Remembered, you still need to be inside your droplet using Putty or a Linux terminal connected to SSH:

    mysqldump -u DBusername -p dbname -h host > websitedatabase.sql
    

    This will ask for your password which again you can take from that env.php file. Paste it and wait for the command to finish. Once it finishes, you’ll have a file called websitedatabase.sql which will contain your database. Copy it over locally using the rsync or scp command presented above.

Hello there,

You cannot currently download DigitalOcean backups or snapshots however, as an alternative, you can back up data locally using third-party tools like rsync or SFTP.

To Export a database, open up a terminal, making sure that you are not logged into MySQL and type:

mysqldump -u [username] -p [database name] > [database name].sql

The database that you selected in the command will now be exported to your droplet.

To share your support for this feature, vote for downloading snapshots and backups on ideas.digitalocean.com.

https://ideas.digitalocean.com/ideas/DO-I-2423

Hope that this helps!
Regards,
Alex

by Justin Ellingwood
Rsync is a tool for intelligently syncing local and remote directories. In this article we will explore the basic usage of this utility to copy files from directory to directory and from system to system.