Mist Network
Follow channel
Support

How to Back Up a VPS: Files, Databases and Off-Server Copies

A VPS gives you full control — and full responsibility for your data. Here is what to back up, how to automate it with a few commands, where to store the copies and how to make sure you can actually restore them.

Updated: 2 min read
How to back up a VPS — files and database dumps copied from a server to off-site storage

To back up a VPS, copy three things off the server on a schedule: your website and application files, your database dumps and your configuration. Store the copies somewhere other than the VPS itself, encrypt them, keep several versions and test a restore from time to time. A backup that lives on the same server is not a backup.

This guide explains what to include, shows simple commands for Ubuntu or Debian, and covers automation, storage and restore tests.

What to back up

WhatTypical locationHow
Website and app files/var/www, /home, /srvArchive or sync the folders
DatabasesMySQL / MariaDB, PostgreSQLDump to a file first, then copy the dump
Configuration/etc (web server, PHP, cron, firewall)Archive the relevant folders
SSL certificates/etc/letsencryptInclude in the configuration backup
Email (if hosted)Mail directoriesArchive or sync
Key takeaway: never copy a running database's data folder directly. Dump it to a file first, so the backup is consistent.

Step by step: a simple daily backup

  1. Connect to the server — log in over SSH (see how to connect to a VPS via SSH).
  2. Dump the database — for MySQL/MariaDB: mysqldump --single-transaction --all-databases | gzip > /root/backup/db-$(date +%F).sql.gz.
  3. Archive files and config — tar -czf /root/backup/files-$(date +%F).tar.gz /var/www /etc.
  4. Copy off the server — for example rsync -az /root/backup/ user@backup-host:/backups/myvps/, or use restic or BorgBackup for encrypted, versioned backups.
  5. Automate it — put the commands in a script and run it every night with cron (crontab -e).
  6. Clean up — delete local dumps older than a few days so the disk does not fill up.
Tip: restic and BorgBackup encrypt, deduplicate and keep versions for you, so a nightly backup of a large site only uploads what changed.

Where to store backups: the 3-2-1 rule

  • 3 copies of your data — the live server plus two backups.
  • 2 different storage types — for example a second server and object storage.
  • 1 copy off-site — in another data centre or with another provider.

Use a separate account or credentials for the backup storage, so an attacker who gets into the VPS cannot delete the backups too.

How often and how long to keep them

  • Daily for active sites, shops and anything with user data.
  • Before every big change — updates, migrations or new plugins.
  • Keep several versions — for example 7 daily, 4 weekly and a few monthly copies. A problem is not always noticed the same day.

Test a restore

A backup is only useful if it restores. A few times a year, restore the files and database to a test VPS and check that the site works. Note how long it takes — that is your real recovery time.

Important: reinstalling the operating system from the panel wipes the disk. Make sure a recent backup exists off the server before you reinstall, resize or delete a VPS.

Backups as part of security

Backups are your last line of defence after a breach, a broken update or an accidental delete. Combine them with the rest of the VPS security checklist, and if you run WordPress, back up both the files and the database described in how to install WordPress on a VPS.

A VPS you control with mistREG

mistREG runs KVM VPS servers in the EU on NVMe SSD and AMD EPYC with full root access, so you can use any backup tool you like. See the VPS plans, browse our services or ask us on Telegram at @mistnetwork.

Frequently asked questions

What should I back up on a VPS?
Website and application files, database dumps, configuration in /etc including SSL certificates, and email if you host it.
Can I just copy the database folder?
No. Copying a running database's files can give a broken backup. Dump it with mysqldump or pg_dump first and copy the dump.
Where should VPS backups be stored?
Off the server, ideally following the 3-2-1 rule: three copies, two storage types and one copy in another location or provider.
How often should I back up a VPS?
Daily for active sites and shops, plus before every major update or change. Keep several versions.
How do I know a backup works?
Restore it to a test server from time to time and check that the site and database work.

Related articles

Latest articles

All articles
Mist NetworkMist Network