Backup and Restore

LEVEL 0

The Problem

You’re running a production database in Docker with a volume storing critical data:

docker volume create pgdata
docker run -d -v pgdata:/var/lib/postgresql/data postgres:15

The data is safe as long as the host is healthy. But what if:

  • The host crashes and the disk is corrupted?
  • Someone accidentally runs docker volume rm pgdata?
  • You need to migrate to a different server?
  • You need to restore data from last week after a bad migration?

You need backups. How do you backup and restore Docker volumes?