Are docker-hosted databases somehow exempt from backup best practices?

556 views Asked by At

As far as I was aware, for MS SQL, PostgreSQL, and even MySQL databases (so, I assumed, in general for RDBMS engines), you cannot simply back up the file system they are hosted on, but need to do an SQL-level backup to have any hope of internal consistency and therefore ability to actually restore.

But then answers like this and indeed the official docs referenced seem to suggest that one can just tar away on database data:

docker run --volumes-from dbdata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata

These two ideas seem at odds with one another. Is there something special about how Docker works that makes it unnecessary to use SQL-level backups? If not, what am I missing in my understanding? (Why is something used as the official example when you can't use it to back up a production database? That can't be right...)

1

There are 1 answers

4
Gordon Linoff On

Under certain circumstances, it should be safe to use the image of a database on a disk:

  • The database server is not running.
  • All persistent data is on the disk system(s) being backed up (logs, tables spaces, temporary storage).
  • All components are restored together.
  • You are restoring the image to the same server on the same path.

The last condition is important, because some aspects of the database configuration may be stored in operating system files.

You need to do the backup within the database whenever the server is running. The server is responsible for the internal consistency of the data, and the disk image may not be complete or recoverable. If the server is not running, then the state of the database should be consistent in the persistent storage.