Backups and Backup Verification

Verifying the backups you took matters more than taking them. All three databases have two kinds: a physical backup, which copies the data files as a whole, and a logical backup, which extracts objects as SQL or a dump file. Point-in-time recovery (PITR) requires both a physical backup and the logs that follow it (archive logs, WAL, transaction log backups). With a logical backup alone, you can only go back to the moment the dump was taken.

Oracle

Required privileges: SYSDBA or SYSBACKUP (12c+) for RMAN, DATAPUMP_EXP_FULL_DATABASE for a Data Pump full export.

Check archive log mode

Online backups and point-in-time recovery require ARCHIVELOG mode.

SELECT name, log_mode, force_logging, flashback_on FROM v$database;

In NOARCHIVELOG mode, you can only take a consistent backup with the database down (MOUNT), and you can only go back to the time of the last backup.

RMAN full backup

rman target /
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG;
-- To delete archive logs once they are backed up: ... PLUS ARCHIVELOG DELETE INPUT;
  • PLUS ARCHIVELOG switches the log before and after the backup and also backs up the archive logs. Data file backups alone cannot complete a recovery, so take them together.
  • With CONTROLFILE AUTOBACKUP ON, the control file and spfile are backed up separately with every backup. You need this if you lose the control file.
  • Only the default compression (BASIC) is free. LOW, MEDIUM, and HIGH require an Advanced Compression Option license.

Backup job history

SELECT session_key, input_type, status,
       TO_CHAR(start_time, 'YYYY-MM-DD HH24:MI') AS started,
       time_taken_display, input_bytes_display, output_bytes_display,
       ROUND(compression_ratio, 1) AS ratio
FROM v$rman_backup_job_details
WHERE start_time > SYSDATE - 14
ORDER BY start_time DESC;
  • status: COMPLETED, COMPLETED WITH WARNINGS, FAILED, RUNNING, and so on. Investigate WARNINGS too (usually some archive logs could not be read).
  • input_type: DB FULL, DB INCR, ARCHIVELOG, and so on. Check that full backups are COMPLETED on the expected schedule.
LIST BACKUP SUMMARY;
REPORT NEED BACKUP;          -- files lacking backups under the retention policy
RESTORE DATABASE VALIDATE;   -- reads the backup pieces to validate them without actually restoring

Clean up the backup catalog (CROSSCHECK, DELETE)

CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
DELETE EXPIRED BACKUP;       -- removes only the records of files that are gone
DELETE OBSOLETE;             -- actually deletes backup files outside the retention policy
  • CROSSCHECK checks whether the recorded backup files actually exist on disk or tape, and marks missing ones EXPIRED.
  • If you use the fast recovery area (FRA), check space usage with V$RECOVERY_AREA_USAGE. When it fills up, archiving stops and the database hangs.

WARNING DELETE OBSOLETE and DELETE ... ARCHIVELOG actually delete files. Review the targets with REPORT OBSOLETE; first. You will no longer be able to go back to a point older than the retention policy.

Data Pump logical backup (expdp)

expdp system DIRECTORY=dp_dir DUMPFILE=full_%U.dmp LOGFILE=full_exp.log \
      FULL=Y PARALLEL=4 FLASHBACK_TIME=SYSTIMESTAMP
# Do not put the password on the command line; enter it at the prompt.
  • DIRECTORY is the name of a directory object created in the database (SELECT directory_name, directory_path FROM dba_directories;).
  • With FLASHBACK_TIME, all tables are exported as of the same point in time. Without it, each table is exported at a different time.
  • Use SCHEMAS=hr for a schema and TABLES=hr.employees for a table. It is not a substitute for a physical backup.

PostgreSQL

Required privileges: permission to read the target objects for pg_dump, superuser for pg_dumpall, and for pg_basebackup a role with the REPLICATION attribute plus a replication entry in pg_hba.conf.

Logical backup (pg_dump, pg_dumpall)

pg_dump -h db01 -U postgres -d sales -Fc -f sales.dump          # custom format, compressed
pg_dump -h db01 -U postgres -d sales -Fd -j 4 -f sales_dir      # directory format, parallel
pg_dumpall -h db01 -U postgres --globals-only -f globals.sql    # roles, tablespaces
  • pg_dump dumps a single database and leaves out roles and tablespaces. Take pg_dumpall --globals-only as well.
  • -Fc and -Fd allow selective restore with pg_restore, and only -Fd supports parallel (-j) backup. The default plain format is a SQL file loaded with psql.
  • Supply the password through ~/.pgpass or PGPASSFILE.

Physical backup (pg_basebackup)

pg_basebackup -h db01 -U replicator -D /backup/base_20261126 \
              -Ft -z -X stream -c fast -P
pg_verifybackup /backup/base_plain     # PostgreSQL 13+, verifies a plain-format (-Fp) backup
  • -X stream also receives the WAL generated during the backup, so this backup alone can be opened in a consistent state.
  • -c fast runs a checkpoint immediately at the start. Without it, the backup waits for the next checkpoint.
  • PostgreSQL 17+ has incremental backup (--incremental=<backup_manifest of the previous backup>), which requires summarize_wal = on. Combine the backups with pg_combinebackup when restoring.

Configure WAL archiving

For point-in-time recovery, all WAL after the base backup must be retained.

SHOW wal_level;          -- replica or higher
SHOW archive_mode;       -- on
SHOW archive_command;
# postgresql.conf
archive_mode = on        # changing this requires a restart
archive_command = 'test ! -f /archive/%f && cp %p /archive/%f'
  • %p is the WAL file path and %f is the file name. If the command returns non-zero, PostgreSQL keeps retrying the same file, and pg_wal keeps growing in the meantime.
  • PostgreSQL 15+ can use archive_library (a module) instead of archive_command.

Check archiving status

SELECT archived_count, last_archived_wal, last_archived_time,
       failed_count, last_failed_wal, last_failed_time,
       now() - last_archived_time AS since_last_archive
FROM pg_stat_archiver;
  • If last_failed_time is more recent than last_archived_time, archiving is failing right now. Look for archive command failed in the server log.
  • If low write activity means WAL goes unarchived for a long time, set archive_timeout or force a WAL switch with SELECT pg_switch_wal();.

SQL Server

Required privileges: BACKUP DATABASE/BACKUP LOG permission (db_backupoperator, db_owner, sysadmin). Read permission on msdb to query history.

Check the recovery model

SELECT name, recovery_model_desc, log_reuse_wait_desc, state_desc
FROM sys.databases
ORDER BY name;
  • FULL: point-in-time recovery is possible with log backups. If you do not take log backups, the log file keeps growing (log_reuse_wait_desc = LOG_BACKUP).
  • SIMPLE: there are no log backups, and you can only go back to the time of the last full or differential backup.
  • BULK_LOGGED: bulk operations are minimally logged. You cannot recover to a point inside a log backup interval that contains such an operation.
ALTER DATABASE sales SET RECOVERY FULL;

WARNING Switching from FULL to SIMPLE breaks the log chain, and point-in-time recovery is not possible after that. After switching back to FULL, you must take a full (or differential) backup first before log backups can continue the chain.

Full, differential, and log backups

BACKUP DATABASE sales TO DISK = N'D:\backup\sales_full.bak'
  WITH COMPRESSION, CHECKSUM, STATS = 10;

BACKUP DATABASE sales TO DISK = N'D:\backup\sales_diff.bak'
  WITH DIFFERENTIAL, COMPRESSION, CHECKSUM;

BACKUP LOG sales TO DISK = N'D:\backup\sales_log_202611261400.trn'
  WITH COMPRESSION, CHECKSUM;

-- An ad hoc backup that does not disturb the regular backup sequence
BACKUP DATABASE sales TO DISK = N'D:\backup\sales_adhoc.bak' WITH COPY_ONLY, COMPRESSION;
  • CHECKSUM verifies page checksums during the backup and also stores a checksum in the backup file. If a page is corrupt, the backup fails, so you find out early.
  • COMPRESSION is not available in Express edition. To enable it by default, use sp_configure 'backup compression default', 1.
  • A differential backup contains the changes since the last full backup. A COPY_ONLY full backup is not used as the differential base.

Backup history (msdb.dbo.backupset)

SELECT bs.database_name,
       CASE bs.type WHEN 'D' THEN 'FULL' WHEN 'I' THEN 'DIFF' WHEN 'L' THEN 'LOG' ELSE bs.type END AS backup_type,
       bs.backup_start_date, bs.backup_finish_date,
       CAST(bs.backup_size / 1048576.0 AS decimal(12,1)) AS size_mb,
       CAST(bs.compressed_backup_size / 1048576.0 AS decimal(12,1)) AS compressed_mb,
       bs.is_copy_only, bs.has_backup_checksums, bmf.physical_device_name
FROM msdb.dbo.backupset bs
JOIN msdb.dbo.backupmediafamily bmf ON bmf.media_set_id = bs.media_set_id
WHERE bs.backup_start_date > DATEADD(DAY, -7, GETDATE())
ORDER BY bs.backup_start_date DESC;

Last backup time per database

SELECT d.name, d.recovery_model_desc,
       MAX(CASE WHEN b.type = 'D' THEN b.backup_finish_date END) AS last_full,
       MAX(CASE WHEN b.type = 'I' THEN b.backup_finish_date END) AS last_diff,
       MAX(CASE WHEN b.type = 'L' THEN b.backup_finish_date END) AS last_log
FROM sys.databases d
LEFT JOIN msdb.dbo.backupset b ON b.database_name = d.name AND b.is_copy_only = 0
WHERE d.name <> 'tempdb'
GROUP BY d.name, d.recovery_model_desc
ORDER BY last_full;
  • Look first at databases where last_full is NULL or old, and at FULL-model databases with no last_log.
  • The history does not tell you whether the backup file still exists. Verify files with RESTORE VERIFYONLY (see the restore and point-in-time recovery document).
  • The msdb history keeps growing, so purge old records with EXEC msdb.dbo.sp_delete_backuphistory @oldest_date = '2026-01-01';.