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 ARCHIVELOGswitches 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, andHIGHrequire 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. InvestigateWARNINGStoo (usually some archive logs could not be read).input_type:DB FULL,DB INCR,ARCHIVELOG, and so on. Check that full backups areCOMPLETEDon 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
CROSSCHECKchecks whether the recorded backup files actually exist on disk or tape, and marks missing onesEXPIRED.- 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 OBSOLETEandDELETE ... ARCHIVELOGactually delete files. Review the targets withREPORT 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.
DIRECTORYis 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=hrfor a schema andTABLES=hr.employeesfor 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_dumpdumps a single database and leaves out roles and tablespaces. Takepg_dumpall --globals-onlyas well.-Fcand-Fdallow selective restore withpg_restore, and only-Fdsupports parallel (-j) backup. The default plain format is a SQL file loaded withpsql.- Supply the password through
~/.pgpassorPGPASSFILE.
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 streamalso receives the WAL generated during the backup, so this backup alone can be opened in a consistent state.-c fastruns 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 requiressummarize_wal = on. Combine the backups withpg_combinebackupwhen 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'
%pis the WAL file path and%fis the file name. If the command returns non-zero, PostgreSQL keeps retrying the same file, andpg_walkeeps growing in the meantime.- PostgreSQL 15+ can use
archive_library(a module) instead ofarchive_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_timeis more recent thanlast_archived_time, archiving is failing right now. Look forarchive command failedin the server log. - If low write activity means WAL goes unarchived for a long time, set
archive_timeoutor force a WAL switch withSELECT 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
FULLtoSIMPLEbreaks the log chain, and point-in-time recovery is not possible after that. After switching back toFULL, 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;
CHECKSUMverifies 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.COMPRESSIONis not available in Express edition. To enable it by default, usesp_configure 'backup compression default', 1.- A differential backup contains the changes since the last full backup. A
COPY_ONLYfull 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_fullisNULLor old, and atFULL-model databases with nolast_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
msdbhistory keeps growing, so purge old records withEXEC msdb.dbo.sp_delete_backuphistory @oldest_date = '2026-01-01';.