Skip to content

Instantly share code, notes, and snippets.

@ramonsmits
Created December 30, 2023 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramonsmits/164ff0b44ed24bd2821bf49dc95d4dc5 to your computer and use it in GitHub Desktop.
Save ramonsmits/164ff0b44ed24bd2821bf49dc95d4dc5 to your computer and use it in GitHub Desktop.
Backup restore Postgres between major versions via docker
  1. Ensure that a shared folder exists between the containers. For example, I have the following volume mapping on both instances: - ./backups:/backups
  2. Create a backup via the command pg_dump. For example, the following docker container myapp_db_1:
  • docker exec myapp_db_1 bash -c "pg_dump --username=myuser --no-password --format=c mydatabase > /backups/1.dump"
    
  1. Restore via the command pg_restore on another (newer major) of postgres:
  • docker exec myapp_db_2 bash -c  "pg_restore --username=myuser --no-password --dbname=mydatabase --verbose /backups/1.dump"
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment