Lab 19: Backup & Restore

Time: 40 minutes | Level: Practitioner | DB: MySQL 8.0 + PostgreSQL 15 + MongoDB 7

Backups are insurance. This lab covers the tools every practitioner must know: logical dumps, binary logs (PITR), and document store backups. Tested and verified with Docker.


Step 1 — MySQL: mysqldump Basics

# Full database dump (single database)
docker exec mysql-lab8 mysqldump \
  -uroot -prootpass \
  --single-transaction \
  --routines \
  --triggers \
  labdb > /tmp/labdb_backup.sql

# Verify backup
wc -l /tmp/labdb_backup.sql
head -30 /tmp/labdb_backup.sql

📸 Verified Output:

168 /tmp/labdb_backup.sql

-- MySQL dump 10.13  Distrib 8.0.45, for Linux (x86_64)
-- Host: localhost    Database: labdb
-- Server version 8.0.45
...
CREATE TABLE `orders` (
  `id` int NOT NULL AUTO_INCREMENT,
  `customer` varchar(100) DEFAULT NULL,
...

💡 --single-transaction uses a repeatable-read snapshot for InnoDB tables — no table locks during backup. Critical for production backups without downtime.


Step 2 — MySQL: Backup Options


Step 3 — MySQL: Restore from Dump

📸 Verified Output:


Step 4 — MySQL: Binary Log and Point-in-Time Recovery

💡 Binary log PITR requires: (1) full backup as baseline, (2) binary logs enabled and retained from that point, (3) ability to replay logs up to any point in time.


Step 5 — PostgreSQL: pg_dump

📸 Verified Output:


Step 6 — PostgreSQL: pg_restore and pg_dumpall


Step 7 — PostgreSQL: Point-in-Time Recovery Concept

PostgreSQL PITR uses WAL (Write-Ahead Log) — every change is logged before being applied.

Setup continuous archiving (postgresql.conf):

PITR Recovery workflow:

💡 PITR is PostgreSQL's equivalent to MySQL binary log recovery. It can restore to any second in time as long as WAL files are retained from the base backup.


Step 8 — MongoDB: mongodump and mongorestore

📸 Verified Output:

📸 Verified Output:


Summary

Tool
Database
Format
Use Case

mysqldump

MySQL

SQL text

Logical backup, migration

mysqlbinlog

MySQL

Binary log

PITR, audit

mysqlpump

MySQL

SQL parallel

Faster logical backup

pg_dump

PostgreSQL

SQL / custom / dir

Single database

pg_dumpall

PostgreSQL

SQL text

All databases + globals

pg_restore

PostgreSQL

Restore custom/dir format

pg_basebackup

PostgreSQL

Binary

Physical backup for PITR

mongodump

MongoDB

BSON

Logical collection backup

mongorestore

MongoDB

BSON

Restore collections

mongoexport

MongoDB

JSON/CSV

Export for migration

mongoimport

MongoDB

JSON/CSV

Import from files

Last updated