A reliable cloud server backup has three layers: a provider snapshot before every risky change, a nightly encrypted file and database backup copied off the server, and a restore test you actually run on a schedule. Snapshots alone are not enough, because they usually live on the same platform as the server and are easy to delete along with it. This guide shows how to set up all three on a Linux or Windows cloud VPS, with commands, a retention plan and a restore drill.
It is written for developers and small IT teams in India who run a website, an application or business software on a cloud VPS and want backups they can trust. If you are still planning the business side (laptops, email, SaaS data), start with our cloud backup strategy for small businesses and come back here for the server work.
Snapshots vs backups: what each one protects you from
People use the two words as if they mean the same thing. They do not, and the difference decides what you can recover.
| Provider snapshot | File and database backup | |
|---|---|---|
| What it copies | The whole disk at one moment | Chosen folders plus consistent database dumps |
| Where it lives | Usually on the same cloud platform | Wherever you send it: another server, object storage, another provider |
| Best for | Rolling back a failed upgrade or config change | Recovering deleted files, a corrupted database, or the whole server after a compromise |
| Restore granularity | All or nothing (whole disk) | A single file, one database, or everything |
| Database safety | Crash-consistent at best; a busy database may need recovery on boot | Consistent if you dump with the right flags |
| Weak spot | Lost if the account or platform is the problem | Useless if nobody tests restores |
Think of snapshots as an undo button and backups as insurance. You need both. Take a snapshot before every OS upgrade, control panel install or major deploy, and delete it a few days later once you are sure the change is good. Old snapshots also add to your monthly bill.
Decide what to back up and how often
Before you install anything, write down two numbers for each server, in plain words:
- How much work can you lose? (the recovery point objective, RPO). For a brochure website, one day is usually fine. For a store that takes orders all day, an hour may already be painful.
- How long can you be down? (the recovery time objective, RTO). This decides whether a restore from offsite storage is fast enough, or whether you also need a ready standby server.
Then list what actually needs copying. On a typical Linux cloud server that is a short list:
/etc: Nginx or Apache config, systemd units, cron jobs, firewall rules.- Application code and uploads, for example
/var/wwwor/srv/app. Code is often in Git already; uploads are not. - Database dumps (never the raw MySQL or PostgreSQL data directory while the service is running).
- TLS certificates in
/etc/letsencrypt, so a restored server does not hit certificate rate limits. - Any
.envor secrets file. Back it up, but only into an encrypted repository.
You do not need to copy /usr, /proc, package caches or logs you never read. A fresh OS install plus your file list is quicker to restore than a full-disk image, and much smaller to store.
Back up a Linux cloud server step by step
The four steps below give you consistent database copies, an encrypted history stored away from the server, a schedule that survives reboots, and protection against someone deleting that history.
Step 1: consistent database dumps
Copying database files while the database is writing gives you a backup that may not open. Dump it to a file first, then back up the file. Create a folder only root can read:
sudo install -d -m 700 /var/backups/db
For MySQL or MariaDB with InnoDB tables, --single-transaction takes a consistent copy without locking the site:
sudo mysqldump --single-transaction --routines --triggers --events \
--all-databases | gzip > /var/backups/db/mysql-$(date +%F).sql.gz
For PostgreSQL, the custom format (-Fc) is compressed and lets you restore one table at a time with pg_restore:
sudo -u postgres pg_dump -Fc appdb > /var/backups/db/appdb-$(date +%F).dump
Keep only a few days of dumps on the server itself, for example with find /var/backups/db -type f -mtime +3 -delete. The long history belongs in the offsite repository, not on the same disk.
Step 2: encrypted offsite backups with restic
restic is a free, open-source backup tool that encrypts everything before it leaves the server, stores only changed data after the first run, and can back up to another server over SFTP or to S3-compatible object storage. It is in the Ubuntu and Debian repositories:
sudo apt update && sudo apt install restic
Pick a destination that does not share fate with the server: a small second VPS, object storage, or storage with another provider. For SFTP, create an SSH key for root (sudo ssh-keygen -t ed25519) and add its public key to the backup user on the destination. Store the repository password in a root-only file and keep a second copy in your password manager. Without it, nobody can restore, including you.
sudo install -m 600 /dev/null /root/.restic-pass
sudo nano /root/.restic-pass # paste a long random password
export RESTIC_REPOSITORY="sftp:backup@203.0.113.10:/srv/restic/web01"
export RESTIC_PASSWORD_FILE=/root/.restic-pass
sudo -E restic init
Run the first backup by hand and check the output:
sudo -E restic backup /etc /var/www /var/backups/db /etc/letsencrypt \
--exclude-caches --tag nightly
sudo -E restic snapshots
The first run uploads everything. Later runs only send changed chunks, so a nightly job on a typical website server is small, even on a modest uplink.
Retention. A sensible starting point for most business servers is 7 daily, 4 weekly and 6 monthly copies. restic removes the rest and frees the space:
sudo -E restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
Adjust it to your data. If you keep personal data, do not keep backups longer than you can justify (see the DPDP section below).
Step 3: schedule it with a systemd timer
A systemd timer is easier to monitor than a cron line: it logs to the journal, and Persistent=true runs a missed job after a reboot. Put the dump and backup in one script, /usr/local/sbin/nightly-backup.sh:
#!/bin/bash
set -euo pipefail
export RESTIC_REPOSITORY="sftp:backup@203.0.113.10:/srv/restic/web01"
export RESTIC_PASSWORD_FILE=/root/.restic-pass
mysqldump --single-transaction --routines --triggers --events --all-databases \
| gzip > /var/backups/db/mysql-$(date +%F).sql.gz
find /var/backups/db -type f -mtime +3 -delete
restic backup /etc /var/www /var/backups/db /etc/letsencrypt --exclude-caches --tag nightly
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
restic check
Make it executable with sudo chmod 700 /usr/local/sbin/nightly-backup.sh, then create the service and timer:
# /etc/systemd/system/nightly-backup.service
[Unit]
Description=Nightly database dump and restic backup
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/nightly-backup.sh
# /etc/systemd/system/nightly-backup.timer
[Unit]
Description=Run nightly backup at 02:30
[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
RandomizedDelaySec=10m
[Install]
WantedBy=timers.target
sudo systemctl daemon-reload
sudo systemctl enable --now nightly-backup.timer
systemctl list-timers nightly-backup.timer
sudo systemctl start nightly-backup.service # run once now
journalctl -u nightly-backup.service -n 50
If your server's timezone is set to Asia/Kolkata, 02:30 means 2:30 am IST, a quiet hour for most Indian websites. If you have not set the timezone yet, our first 30 minutes on a new Ubuntu VPS guide covers it, along with the baseline snapshot.
Step 4: protect backups from ransomware and mistakes
An attacker who gets root on your server can read /root/.restic-pass and the SSH key used for SFTP. If that key can also delete old backups, the attacker can wipe your history before encrypting the server. Close that gap:
- Append-only destination. restic's
rest-serverhas an--append-onlymode: the server can add new backups but cannot delete old ones. Runforget --prunefrom a separate, trusted machine instead. - Object lock. If you use S3-compatible storage that supports object lock or bucket versioning, turn it on so deleted objects can be recovered for a set period.
- Separate credentials. The backup account should not be able to log in to anything else, and it should not be the same user as your website deploy key.
- Alert on silence. A backup that stops running fails quietly. Add a check that alerts you if the newest snapshot is more than 26 hours old. A free heartbeat service, or a small script that parses
restic snapshots --latest 1 --json, is enough. - Watch the size. A nightly backup that is suddenly much smaller than usual often means a mount failed or a database dump came out empty.
Test restores every month
This is the step most teams skip, and the one that decides whether you get your data back. Do a small test every month and a full one every quarter.
Monthly: restore a few files and verify data
sudo -E restic restore latest --target /tmp/restore-test --include /etc/nginx
diff -r /etc/nginx /tmp/restore-test/etc/nginx && echo "nginx config matches"
sudo -E restic check --read-data-subset=5%
check --read-data-subset actually downloads and verifies a sample of the stored data, which catches corruption that a plain check does not.
Quarterly: rebuild the server from scratch
- Create a new, small cloud VPS with the same OS version.
- Install restic, copy in the password file, and restore the latest snapshot to
/tmp/restore. - Install the web stack and copy back
/etcfiles, site files and certificates. - Import the database:
gunzip -c mysql-DATE.sql.gz | mysqlorpg_restore -d appdb appdb-DATE.dump. - Point your hosts file (not public DNS) at the new IP, open the site, log in, and check that recent orders or records are there.
- Write down how long it took. That is your real RTO. If it is longer than the business can accept, fix the process or keep a standby server.
- Delete the test server so it does not add to the bill.
Windows cloud VPS backups
The same three layers apply on a Windows Server VPS. Take a provider snapshot before Windows updates or software upgrades. For scheduled backups, install the built-in Windows Server Backup feature from an elevated PowerShell:
Install-WindowsFeature Windows-Server-Backup
wbadmin start backup -backupTarget:\\backup01\winbackup -include:C: -allCritical -quiet
A backup to a network share keeps only the latest copy, so it is not a history on its own. Copy the backup folder or your application's data files offsite with a tool that keeps versions; restic also runs on Windows. For SQL Server, schedule a native BACKUP DATABASE to a local folder and include that folder in the offsite job, the same way as the Linux dumps. Remote Desktop servers are a common ransomware target, so the append-only and alerting advice above matters even more here. For running Windows workloads, see Windows cloud VPS.
DPDP, data location and GST: India-specific points
- Backups are personal data too. If your database holds customer names, phone numbers or email addresses, every backup copy holds them as well. The Digital Personal Data Protection Act, 2023 expects data fiduciaries to take reasonable security safeguards against a personal data breach, so encrypt backups and limit who holds the keys. The official text is on the MeitY data protection page.
- Retention. Keep a written note of how long backups are kept and why. When a customer's data must be erased, it ages out of backups within that window instead of living for years.
- Location. The Act does not ban storing data outside India in general, but transfers can be restricted to countries the government notifies, and many sector rules are stricter. Keeping both the server and the offsite copy in India is the simplest position to explain to customers and auditors. Our article on the DPDP Act and hosting in India covers this in more detail.
- Restore speed. Pulling a large backup from storage abroad over a long route takes longer than from a nearby data centre. If your RTO is tight, measure the restore time from the location you chose.
- Billing. If backup storage is a separate line item, ask for a GST invoice in INR so the cost can be claimed like the server itself, and add it to your monthly cost review.
How AvertHost can help
AvertHost Linux cloud VPS plans run in a Tier-IV data centre in Delhi, so the server and its data stay in India. The plans listed on the Linux VPS page include a separate NVMe backup allocation alongside the main disk, and automated daily and weekly backup options are available. You get root access to run restic or any other backup tool yourself, with a 99.9% uptime SLA and 24/7 support. Billing is in INR with GST invoices. If you want help designing a backup and restore-test schedule for your workload, our support team can talk it through with you.
FAQ: cloud server backup
Is a snapshot enough to back up my cloud server?
No. A snapshot is a quick rollback point, but it usually sits on the same platform as the server and restores the whole disk only. Keep an encrypted file and database backup in a separate location as well.
How often should I back up a cloud VPS?
Nightly suits most websites and business apps. Databases that change all day, such as an online store, may need more frequent dumps or database replication. Let the amount of work you can afford to lose decide.
Where should I store cloud server backups?
Somewhere that does not fail with the server: another server, object storage, or another provider, with credentials the main server cannot use to delete history. Keeping it in India keeps restores fast and DPDP questions simple.
How do I know my backups actually work?
Restore them. Restore a few files and verify a data sample each month, and rebuild a full test server from backup each quarter, timing how long it takes.