Home>

There is a postgresql database in docker. The task is to set up an incremental backup. In creating a container, scripts are written for creating users, databases and rights, forwarding files from the container to the system. What do I do next:

  1. "apk add rsync"and"apk add openssh"... Then through "su -postgres"I set up an ssh key and forward it to myself locally, so that in the future I can set commands to save wal files to myself locally (in the future, to another server to store these files securely).

  2. Then I create daddies for backup in docker, I format the config, namely: replica /archive, off to on and write commands for writing and restoring wal. I do this via sed.

  3. Create a savepoint, or whatever it is like to call it:

    su -postgres psql -c "SELECT pg_start_backup ('label');" postgres tar -C /var /lib /postgresql /data /-czvf /stor/backups/pg_basebackup_backup.tar.gz. psql -c "SELECT pg_stop_backup ();" postgres

  4. Then I pump up the database and wal files are written to me locally, everything is OK with that.

  5. Next, you need to test how recovery will work, you need to break and build. And here are the problems.

In general, I managed to recover after deleting files, but this was not always the case and without understanding how it exactly works. In the instructions, you need to stop the database, delete the files, unzip the point that we created, write the command to restore the wal files (I do this right away) and start the database.

But in docker, there is no way to stop postgresql as I understand it. I put the data folder right in the docker, then unpack the backup start point there and restart the docker. And here I do not understand what is happening. Sometimes the container falls down and cannot be lifted again. Sometimes everything is restored.

I need to understand exactly how it works and how to use it. I thought that if I have a mount point and a set of wal files, then I can create a new container, replace data, and start a file restore. But it doesn't work that way. It seems to me that this is how it should work, but I didn't manage to google such a task. Do not hit (

  • Answer # 1

    Made docker on ubuntu, then installed postgres there. The problem was that you need to stop postgres 100% during recovery. In a docker on an alpine, it was impossible to do this, when the postgression process was stopped, it would fall. And now everything works fine.

  • Answer # 2

    Made docker on ubuntu, then installed postgres there. The problem was that you need to stop postgres 100% during recovery. In a docker on an alpine, it was impossible to do this, when the postgression process was stopped, it would fall. And now everything works fine.