How to back up a website to your own computer: database and files

A website has two parts: a database and a folder of files. A full website backup is a copy of both, taken at the same time and kept somewhere other than the same server.

What a website backup includes

Cache, temp files and logs don't need saving: they only make the archive bigger.

Step 1. The database

The database login is in the site's config, for example wp-config.php. The dump is one SSH command:

ssh deploy@example.com "mysqldump --single-transaction --routines --triggers --events site | gzip" \
  > site-db-$(date +%F).sql.gz

More on the flags and on keeping the password private in "Back up MySQL over SSH to your Mac".

Step 2. The files

tar packs the site folder on the server and the archive streams straight to your Mac:

ssh deploy@example.com "tar -czf - --exclude='site/wp-content/cache' -C /var/www site" \
  > site-files-$(date +%F).tar.gz

-C /var/www site keeps short paths like site/… inside the archive, and --exclude skips the cache. Change the site path and cache folder to yours. If there are lots of uploads, fetching only the changes beats a full archive every time, see "Incremental backups with rsync".

Step 3. Check the copy

tar -tzf site-files-2026-10-18.tar.gz > /dev/null && echo "archive OK"
gunzip -c site-db-2026-10-18.sql.gz | tail -n 1

The first command reads the archive to the end; the second should print -- Dump completed on ….

Where to keep it

A copy on the same server won't help if the server dies, the host suspends the account or someone deletes the whole site. A good rule is 3-2-1: three copies, on two different kinds of storage, one of them somewhere else. For a small project that's the live server, your Mac and the cloud.

How often

As often as the amount of data you can afford to lose. A blog is fine weekly; a shop taking orders needs a daily backup or one every few hours.