Database backup

On this page 7

A database backup is a consistent, restorable copy of the data, metadata and transaction history of a database, stored separately from the live system so that the database can be rebuilt after hardware failure, human error, corruption or attack. In databases, backup is only half of the discipline known as Backup & recovery: a copy has value only if it can be restored within an agreed time to an agreed point in time.

Unlike a simple file copy, a proper database backup must respect transactional consistency. A database engine constantly modifies pages in memory and on disk, so copying data files while the server writes to them usually produces an unusable image unless the engine coordinates the process or the copy is paired with the matching transaction logs.

How a database backup preserves consistency

A database backup preserves consistency by capturing either a logical view of committed data at one moment or a physical image of data files together with the log records needed to repair them. Logical tools such as pg_dump and mysqldump read the data through a transaction snapshot, so every table reflects the same instant. Physical tools such as pg_basebackup, Percona XtraBackup and RMAN copy data blocks while the server runs, and the engine later replays the write-ahead log or redo log to bring the copied blocks to a consistent state.

The log is therefore central to almost every serious backup strategy. Relational engines record each change in a sequential log before it reaches the data files, which allows crash recovery after a power loss. Backup systems reuse the same mechanism: by archiving the log continuously, an administrator can restore a base copy and then roll forward to any moment covered by the archive, which is the basis of point-in-time recovery.

The following table summarizes the main components that a complete backup set usually contains and why each one matters.

ComponentWhat it containsWhy it is needed
Base backupFull copy of data files or logical exportStarting point for every restore
Log archiveWAL segments, binary logs or redo logsRoll forward to a chosen moment
MetadataUsers, roles, configuration, schemaRebuild a working server, not only tables
Catalog or manifestList of files, checksums, timestampsVerify completeness before restoring
Encryption keysKeys for encrypted backups or tablespacesWithout them the copy is unreadable
Components of a complete backup set

Types of database backup

Database backups are classified by what is copied, how much is copied and whether the database stays online. These dimensions combine freely: a hot physical incremental backup and a cold logical full backup are both valid designs. The choice determines backup duration, storage cost and, above all, restore speed.

TypeHow it worksMain advantageMain drawback
Full backupCopies the entire databaseSimplest, self-contained restoreSlow and large for big databases
Differential backupCopies changes since the last full backupRestore needs only two setsGrows daily until the next full
Incremental backupCopies changes since the last backup of any kindSmallest and fastest to takeRestore must apply a long chain
Transaction log backupCopies log records since the previous log backupEnables point-in-time recoveryUseless without a valid base
Logical backupExports rows and schema as SQL or a portable formatPortable across versions and platformsSlow restore with index rebuilds
Physical backupCopies data blocks or filesFast restore of large databasesTied to engine version and layout
Main backup types and their trade-offs

Availability is the second axis. A hot backup runs while the database accepts reads and writes, a warm backup allows reads only, and a cold backup requires a clean shutdown. Hot backups are standard in production because few systems can accept nightly planned downtime.

A database backup is not the same as replication, a storage snapshot or high availability, although all of them protect data. The decisive difference is isolation in time and space: a backup keeps older versions on separate storage, while replication faithfully copies every change, including an accidental DROP TABLE or ransomware encryption, to the replica within seconds.

TechniqueProtects againstDoes not protect against
Database backupDeletion, corruption, ransomware, site lossDowntime during a long restore
ReplicationServer or node failureLogical errors that replicate instantly
Database snapshotRecent mistakes on the same systemLoss of the underlying storage array
Log shippingPrimary site failure with some lagErrors replayed before detection
Crash recoveryPower loss and process crashesLost or damaged data files
How backup differs from neighboring techniques

Features such as Oracle Flashback or delayed replicas shorten recovery from human error, yet they complement rather than replace an off-system backup chain.

Designing a backup strategy around RPO and RTO

A backup strategy is designed backward from two business targets. The recovery point objective (RPO) states how much recent data the organization can afford to lose, and the recovery time objective (RTO) states how long the service may stay unavailable during a restore. A daily full backup alone gives an RPO of up to 24 hours; adding continuous log archiving can reduce it to seconds or minutes.

The decision table below shows typical starting configurations; real designs also weigh database size, change rate, network bandwidth and regulatory duties.

SituationRecommended approachReason
Small database, tolerant RPONightly logical dumpSimple, portable, cheap to store
Large OLTP system, strict RPOWeekly physical full, daily incremental, continuous log archivingMinimizes data loss and backup window
Strict RTO for multi-terabyte dataPhysical backups plus standby replicaRestoring from scratch would take too long
Ransomware exposureImmutable, offline or air-gapped copiesAttackers often delete reachable backups
Legal retention dutiesDefined backup retention policy with tiered storageKeeps required history at controlled cost
Typical strategy choices by requirement

Many teams follow the 3-2-1 rule: at least three copies of the data, on two different media types, with one copy off-site. Current practice often extends it with one immutable copy and zero unverified backups, because a backup that has never been restored is an assumption rather than a safeguard.

Common failures and how to prevent them

Most backup failures are discovered only during an emergency restore, which is the worst moment to learn that the strategy does not work. Experienced administrators treat restore testing as part of the backup process, measuring actual restore duration against the RTO and checking data integrity after each test.

  • Broken log chains: a missing WAL segment or binary log makes point-in-time recovery impossible beyond the gap; monitor archiving continuously.
  • Copying live files without coordination: a plain file copy of a running server is usually inconsistent; use engine-aware tools.
  • Lost encryption keys: encrypted backups without their keys cannot be restored at all.
  • Silent corruption: copying corrupted pages preserves the corruption; enable checksums and validate backups.
  • Untested restores: procedures, credentials and tooling drift until nobody can perform a restore under pressure.

Stripped to the essentials

A database backup is a safety copy of everything a database knows, kept somewhere else so it survives when the original breaks. If someone deletes the wrong records, a disk dies or malware scrambles the files, the copy lets the team put the data back.

Think of it like saving versions of an important document, plus a diary of every edit made since the last save. With the saved version and the diary, the document can be rebuilt as it looked at almost any moment. The key point is simple: a backup only counts if it can actually be restored, so good teams practice restoring regularly.

Where it is applied

An online retailer runs a 2 TB PostgreSQL database that handles orders around the clock. The team takes a physical base backup with pgBackRest every Sunday, incremental backups every night and continuous WAL archiving to object storage in a second region, with a copy locked against deletion for 30 days.

On a Wednesday at 14:05, a faulty deployment script deletes the shipping addresses of recent customers. The replica receives the same deletion within a second, so it cannot help. The administrators restore the latest base and incremental backups to a new server and replay the archived log up to 14:04:30, just before the script ran.

The restored data is ready in about two hours, within the agreed recovery time, and the missing addresses are copied back into production. The team loses no orders, because the regular quarterly restore drills had already confirmed that the procedure and timings were reliable.