Linux Server Backup and Recovery: Best Practices
Linux backup and recovery best practices: set RPO and RTO, keep offsite and immutable copies, encrypt, automate with restic or rsync, test restores.
Backup and recovery best practices for a Linux server come down to five habits: decide your recovery point and recovery time targets first, keep at least one copy off the server and one copy that cannot be altered, encrypt everything that leaves the machine, automate the jobs and their alerts, and restore from backup on a schedule so you know it works. Everything else is detail in service of those habits.
This guide is about the recovery side of the job: how to plan, check and rehearse a restore on a single Linux server or a small fleet. If you want the scripting basics first, read our walkthrough on automating Linux backups with rsync and cron, and for distribution-specific steps see the RHEL 10 backup and restore guide. Both sit under our RHEL 10 beginner's guide, the starting point for the Linux topics on this blog.
Key takeaways
- Write down a recovery point objective (RPO) and recovery time objective (RTO) for each server before choosing tools. Backup frequency follows from RPO; restore method follows from RTO.
- Copying files to another disk is not a backup plan. You need versions, an offsite copy, and a copy that ransomware or a mistyped command cannot delete.
rsync -adoes not preserve ACLs, extended attributes or hard links. Add-A,-Xand-Hwhen those matter.- Tools such as restic encrypt the repository and can verify stored data with
restic check --read-data-subset. - A backup you have never restored is a guess. Schedule restore drills and record how long they take.
Start with RPO and RTO, not with a tool
Recovery point objective is how much data you can afford to lose, measured in time. If the business can live with losing four hours of changes, a backup every four hours meets the target. Recovery time objective is how long the service can stay down while you restore. AWS uses these two terms throughout its disaster recovery whitepaper, and they work just as well for a single on-premises box: the frequency of your backups sets the recovery point you can achieve, and the restore method sets your recovery time.
Write the two numbers down per server, and get the application owner to agree to them. A database that takes orders may need an RPO of minutes, which pushes you toward database-native log shipping or replication on top of nightly dumps. A build agent that can be rebuilt from configuration management may need no data backup at all, only a copy of its configuration and a tested rebuild playbook. Without the numbers, every server gets the same nightly job and nobody knows whether that is too much or far too little.
The targets also tell you what to back up. For most Linux servers the list is short: application data, database dumps or snapshots, /etc, cron tables, TLS certificates and keys, and any locally installed scripts. Operating system binaries rarely need backing up if you can reinstall from a known image and reapply configuration. Many teams find their restore gets faster once they stop treating the whole filesystem as precious.
The copies you need
A common rule of thumb is three copies of the data, on two different kinds of storage, with one copy offsite. It is a useful starting checklist, but the more important questions are about failure modes. Ask what happens if the server's disk dies, if someone runs a bad rm, if an attacker gets root, and if the whole site or cloud region is unavailable. Each copy should cover at least one of those cases.
| Threat | What protects you | Example on Linux |
|---|---|---|
| Disk or host failure | Copy on separate hardware | Nightly push to a backup server or object storage |
| Accidental deletion or bad deploy | Versioned snapshots with retention | restic or Borg snapshots kept for days, weeks and months |
| Ransomware or compromised root | A copy the server cannot delete or overwrite | Pull-based backups, or object storage with versioning and object lock |
| Site or region outage | Copy in another location | Replication to a second region or provider |
| Silent corruption | Integrity checks on the backup data | restic check --read-data-subset |
The ransomware row is the one most small setups miss. If the server holds credentials that can delete its own backups, then an attacker with root on that server can delete them too. Two common fixes are a pull model, where a separate backup host connects in and copies data out, and storage that refuses deletes for a retention period. AWS's disaster recovery guidance makes a related point about replication: continuous replication gives a near-zero backup delay but may not protect against corruption or malicious deletion as well as point-in-time backups do. Replication is not a substitute for versioned backups.
Choosing a backup method
rsync for file copies
rsync is installed almost everywhere and is good at moving only what changed. Its archive flag is often misunderstood. According to the rsync manual, -a equals -rlptgoD and does not include ACLs (-A), extended attributes (-X) or hard links (-H). On a server that uses SELinux labels, POSIX ACLs or hard-linked files, a plain rsync -a backup will restore files that look right but behave differently.
# Preview first, then run the real copy with ACLs, xattrs and hard links
rsync -aAXH --delete --dry-run /srv/app/ backup@backup01:/backups/app01/current/
rsync -aAXH --delete /srv/app/ backup@backup01:/backups/app01/current/
Use --delete with care. It removes files from the destination that no longer exist at the source, which is what you want for a mirror and exactly what you do not want if the source was just wiped. That is why a mirror alone is not a backup. Pair it with snapshots on the destination, or use --link-dest to build dated directories where unchanged files are hard-linked to the previous run.
Snapshot-based tools such as restic
Deduplicating tools keep many versions without storing every file many times, and they handle retention for you. restic is a good example. Its documentation states that the repository contents are encrypted and authenticated, using AES-256 in counter mode with a Poly1305-AES MAC. The latest release on its GitHub page at the time of writing is 0.19.1, from July 2026.
# Create a repository once, then back up on a schedule
restic -r /srv/restic-repo init
restic -r /srv/restic-repo backup /etc /srv/app /var/backups/db
# Apply a retention policy and remove unreferenced data
restic -r /srv/restic-repo forget --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --prune
# Verify repository structure, plus read back 10% of the stored data
restic -r /srv/restic-repo check --read-data-subset=10%
The retention flags keep the most recent snapshot for each of the last seven days, five weeks and twelve months. Run forget with --dry-run the first time to see what it would remove. The subset check matters because a plain check verifies structure, while --read-data downloads every pack file; the subset form spreads that cost over several runs.
Filesystem and volume snapshots
LVM, Btrfs, ZFS and cloud block storage can all take point-in-time snapshots. They are quick and great for rolling back a bad upgrade, but a snapshot on the same storage pool dies with that pool. Treat a local snapshot as a convenience layer, and copy the data somewhere else for real protection. On AWS, our guide on EBS snapshots for EC2 backup covers how that works.
Databases need their own path
Copying the data directory of a running database usually gives you a backup that will not start. Use the database's own tools: a logical dump, a physical backup tool that understands the engine, or storage snapshots taken after the database has flushed and frozen writes. Back up the output of those tools, not the live files. If your RPO is tight, add the engine's write-ahead or binary logs so you can replay changes up to a point in time.
Encrypt, and protect the keys
Any copy that leaves the server should be encrypted, and in most organisations the local copies should be too. Encryption at rest on the backup target is good, but client-side encryption is better because the storage provider and anyone who steals the bucket credentials only see ciphertext.
The weak point is the key. Store the repository password or key in a secrets manager or a sealed offline location, and make sure at least two people can retrieve it during an incident. A surprising number of failed restores are not caused by bad data. The data is fine, but the only copy of the password lived on the server that just died. Write the key location into the runbook and test retrieving it as part of every restore drill.
Automate the job and watch it
Schedule backups with cron or systemd timers, and make the job loud when it fails. A backup script should exit non-zero on any error, log to the journal or a file you ship to central logging, and report success to monitoring. A common pattern is a "dead man's switch": the job pings a monitoring endpoint when it finishes, and an alert fires if no ping arrives within the expected window. That catches the case where cron itself stopped running, which a failure email will never catch.
Track a few numbers per server: time of the last successful backup, size of the last backup compared with the average, and duration. A sudden drop in size often means a path changed or a mount was missing. A sudden jump can mean a log directory slipped into the include list, or that files were encrypted by something hostile and now look like all-new data.
Keep the backup configuration itself in Git and deploy it with your configuration management tool, so a rebuilt server gets the same job. If you use Ansible, a small role that installs the tool, writes the include and exclude lists, and enables the timer is enough for most fleets.
Test restores on a schedule
This is the practice that separates a backup system from a hope. AWS's disaster recovery whitepaper says plainly that a backup strategy must include testing the backups, and the same is true off the cloud. A restore test answers three questions: can we read the data, is it complete and consistent, and how long does it take?
- Pick a server and a random snapshot, not always the latest one.
- Restore to a scratch location or a throwaway VM, never over the live data. With restic,
restic -r /srv/restic-repo restore latest --target /tmp/restoredoes this. - Check the result: compare file counts and checksums for a sample, start the application against the restored data, and for databases run a query that proves the data is current to the expected point.
- Record the elapsed time and compare it with the RTO. If a full restore takes six hours and the RTO is two, you have found the gap before an outage did.
- Update the runbook with anything that surprised you, such as a missing package, a permission problem or an undocumented step.
Run a small file-level restore weekly and a full server rebuild at least a few times a year. Rotate who does the drill. If only one person can restore a server, that person is a single point of failure.
Write the recovery runbook
When a server is down, nobody wants to read man pages. A one-page runbook per service should say where the backups live, how to get the key, which command restores what, the order of steps (base OS, configuration, data, application, verification), and who to tell. Include the commands verbatim. Store the runbook somewhere that does not depend on the server it describes. Our post on automating incident response with runbooks covers how to keep these documents current.
A restore during an outage is also a change to production. Restore into a clean location first, verify, then switch over. Restoring straight over a corrupted directory can mix good and bad files in ways that are hard to untangle.
Retention, cost and compliance
Retention is a business decision with a technical cost. Longer retention protects you against problems discovered late, such as corruption that went unnoticed for weeks, but costs storage and can conflict with data protection rules that require deletion. Agree on a policy per data type, encode it in the tool (for restic, the forget flags), and document it. If you store backups in cloud object storage, lifecycle rules can move older copies to cheaper storage classes; check the minimum storage duration of the class before you do, because early deletion can still be billed.
Backups often contain the most sensitive data in the company, all in one place. Restrict who can read them, log access, and include backup storage in your access reviews. The broader cloud backup practices guide covers this for cloud-native workloads.
A practical baseline for one server
If you are starting from nothing, this baseline covers most small production servers:
- Nightly restic backup of
/etc, application data and database dumps to a repository on another host or in object storage, with client-side encryption. - A database dump job that runs before the file backup and writes to
/var/backups/db. - Retention of seven daily, five weekly and twelve monthly snapshots, adjusted to your policy.
- Monitoring that alerts when no successful run has been seen for 26 hours.
- A weekly
restic check --read-data-subsetrun and a monthly restore drill to a scratch VM. - A copy that the production server cannot delete, using a pull-based job or locked object storage.
From there, tighten the schedule for servers with stricter RPOs, and add replication where the RTO demands a standby instead of a restore.
Learning the skills
Backup and recovery work draws on everyday Linux administration: permissions, SELinux contexts, systemd timers, LVM, and shell scripting. Our Linux administration course covers these in the Kharadi, Pune classroom and live online across India, and the RHCSA course adds the Red Hat exam objectives for storage and system recovery.
Frequently asked questions
How often should I back up a Linux server?
As often as your recovery point objective requires. If losing a day of data is acceptable, nightly is enough. If you can lose only minutes, add database log shipping or replication on top of regular backups.
Is rsync enough for backups?
rsync is fine for moving data, but a single mirror is not a backup because deletions and corruption are copied too. Combine it with versioned snapshots, and add -A, -X and -H if you need ACLs, extended attributes and hard links.
What is the 3-2-1 backup rule?
It is a rule of thumb: keep three copies of data, on two kinds of storage, with one copy offsite. Many teams also add a copy that cannot be modified or deleted, to protect against ransomware.
How do I test that my backups work?
Restore a random snapshot to a scratch location, check file counts and checksums, start the application against the restored data, and time the whole process against your recovery time objective.
Should backups be encrypted?
Yes, at least every copy that leaves the server. Prefer client-side encryption, and store the key somewhere that survives the loss of the server, such as a secrets manager, with more than one person able to reach it.
How do I protect backups from ransomware?
Keep at least one copy the production server cannot delete. Use a pull-based backup host or object storage with versioning and object lock, and keep backup credentials off the servers being backed up where possible.
Do I need to back up the whole operating system?
Usually not. If you can rebuild the server from an image and configuration management, back up configuration, application data and database dumps. Full images help when rebuilds are slow or undocumented.
References
- rsync manual page
- restic documentation: working with repositories and checking integrity
- restic documentation: removing snapshots by policy
- restic documentation: restoring from backup
- restic documentation: references and threat model
- Amazon S3 User Guide: storage classes and minimum storage durations
- restic releases on GitHub
- AWS whitepaper: Disaster recovery options in the cloud
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0