Reputation: 12989
Till now I've been backing up my postgresql data using pg_dump
, which exports the data to an sql file mydb.sql
, and then restoring from that sql file using psql -U user -d db < mydb.sql
.
For one reason or another it would be more convenient to restore the database content more directly, in an environment where psql
does not exist... specifically on a host server where postgresql is installed in a docker container running on the host, but not on the host itself.
My plan is to back up the content of /var/lib/postgresql/data/
to a tar file, and when required (e.g. when a new server is created that hosts the postgresql container) just restore that to the same path. The folder /var/lib/postgresql/data/
in the docker container is mapped to a folder on the host server, so I would create this backup on the host, not inside the postgres container.
Is this a valid approach? Any "gotchas"? And are there any subfolders within /var/lib/postgresql/data/
that I can exclude from the tar file? I don't want to back up mere 'housekeeping' information.
Upvotes: 1
Views: 8669
Reputation: 246393
You can do that, but you have to do it properly if you don't want your database to become corrupted.
Either stop PostgreSQL before copying the data directory or follow the instructions from the documentation for an online backup.
Upvotes: 2