Backups

Automatic VPS Server Backups: The 3-2-1 Strategy in Practice

How to set up automatic backups for a Linux VPS: what to back up (files, MySQL/PostgreSQL, configs), how often, where to store it, how to test restores.

EzServer Team 9 min read

Backups are one of those things everyone assumes they have until they actually need one. A corrupted disk, an rm in the wrong directory, ransomware or a deploy that wiped data: what separates a scare from a disaster is having a recent, complete and restorable copy.

The 3-2-1 rule explained

  • 3 copies of your data (the original plus two more).
  • 2 different media or systems (for example, the server disk and external storage).
  • 1 offsite copy, with another provider or in another region.

A backup stored on the same disk as the server is not a backup: if the disk fails or the server is compromised, you lose both.

What a VPS backup must include

ItemExamplesWatch out for
DatabasesMySQL/MariaDB, PostgreSQLUse a consistent dump; never just copy the files of a running database.
Application files/var/www, uploads, storage/User uploads are not in Git.
Environment variables and secrets.env, API keysStore them encrypted.
System configurationNginx/Apache, PHP-FPM, cron, systemdWithout it, rebuilding the server takes hours.
Certificates/etc/letsencryptAvoids mass reissuance and rate limits.

How to create consistent dumps

# MySQL / MariaDB (InnoDB) without locking the database
mysqldump --single-transaction --routines --triggers --all-databases | gzip > mysql-$(date +%F).sql.gz

# PostgreSQL
pg_dump -Fc -d meu_banco -f meu_banco-$(date +%F).dump

How often should you back up?

Define two numbers for each system:

  • RPO (Recovery Point Objective): how much data you can afford to lose. An RPO of 1 hour requires hourly backups.
  • RTO (Recovery Time Objective): how quickly the system must be back online.
System typeDatabaseFilesSuggested retention
E-commerce / SaaSHourlyDaily7 daily + 4 weekly + 3 monthly
Company website / blogDailyWeekly7 daily + 4 weekly
StagingWeeklyWeekly2 to 4 copies

The step almost everyone skips: testing the restore

A backup that has never been restored is just an assumption. At least once a month:

  1. Restore the dump into a temporary database and check the row counts of the main tables.
  2. Make sure the compressed file is not corrupted (gzip -t arquivo.sql.gz).
  3. Time the process: that is your real RTO.

How EzServer automates this

  • Automatic discovery of applications and databases on every server, so nothing gets left out by accident.
  • Scheduled backups of files and databases, with dump verification.
  • Retention policy and cleanup of old copies, so the backups themselves don't fill up the disk (a more common problem than you might think).
  • All in one dashboard, across multiple servers at once.
Beware of a classic mistake: backups written to /tmp or to the same disk, with no retention, fill up the server and take the application down. Always cap the number of local copies.

Frequently asked questions

Isn't my provider's snapshot enough?

Snapshots help, but they live with the same provider and usually copy the whole disk at once. Also keeping file and database backups lets you restore only what you need and protects you against problems with your provider account.

How often should I back up my database?

It depends on how much data you can afford to lose (RPO). For stores and transactional systems, daily is the recommended minimum, and hourly is often better.

Does EzServer find my databases automatically?

Yes. Server discovery identifies applications and MySQL/MariaDB and PostgreSQL databases, so they are added to the backup plan without manual setup.

Manage all your servers in one place

SSH terminal, monitoring, backups and AI. Connect your first VPS in seconds.

Create free account