<optimization>
Assume you have several Docker containers running PostgreSQL — for example, postgres1, postgres2, and so on — and you want to dump their databases and copy them to another server. Doing this manually for each container quickly becomes tedious. Here’s a streamlined approach I use.
Instead of dumping each container manually, combine docker exec with xargs to iterate over them:
docker ps --filter "name=postgres" --format "{{.Names}}" | xargs -I {} docker exec {} pg_dumpall -U postgres > {}.sql
You can then use xargs with scp to transfer all dumps efficiently:
ls postgres*.sql | xargs -I {} scp {} user@remote-server:/path/to/dumps/
Niciun comentariu:
Trimiteți un comentariu