<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-back-up-postgresql-in-docker-local-s3-and-plakar-nick-janetakis-l64ac1yno" -->

---
title: How to Back Up PostgreSQL in Docker (Local, S3, and...
description: A comprehensive guide to backing up PostgreSQL databases running in Docker, covering three approaches: local filesystem, AWS S3, and using Plakar (an open...
canonical: https://daily.dev/posts/how-to-back-up-postgresql-in-docker-local-s3-and-plakar-nick-janetakis-l64ac1yno
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Back Up PostgreSQL in Docker (Local, S3, and Plakar) — Nick Janetakis | daily.dev
og:description: A comprehensive guide to backing up PostgreSQL databases running in Docker, covering three approaches: local filesystem, AWS S3, and using Plakar (an open...
og:url: https://daily.dev/posts/how-to-back-up-postgresql-in-docker-local-s3-and-plakar-nick-janetakis-l64ac1yno
og:image: https://api.daily.dev/og/posts/L64Ac1YNO.png
og:image:alt: How to Back Up PostgreSQL in Docker (Local, S3, and Plakar) — Nick Janetakis
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Back Up PostgreSQL in Docker (Local, S3, and Plakar) — Nick Janetakis

**[Nick Janetakis](https://daily.dev/sources/nickjanetakis)** · 44 min read · 24 upvotes · 2 comments

## Summary

A comprehensive guide to backing up PostgreSQL databases running in Docker, covering three approaches: local filesystem, AWS S3, and using Plakar (an open source deduplication backup tool). Includes shell scripts for automated daily backups via cron, restore procedures, and a cost comparison showing how Plakar's deduplication can reduce S3 storage from ~455 GB to ~65 GB after one year of growth. Also covers Plakar installation, repository setup, snapshot management, pruning policies, and syncing between local and S3 storage backends.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://nickjanetakis.com/blog/how-to-back-up-postgresql-in-docker-local-s3-and-plakar>

## Questions this post answers

### How much can deduplicated backups with Plakar reduce S3 data transfer compared to daily full gzipped pg_dumpall backups?

For a 10 GB database growing about 1% to 2% daily over a year, plain daily gzipped dumps sent to S3 total roughly 12.5 TB transferred, while Plakar's deduplication reduces that to about 64.55 GB transferred over the same year, because Plakar only uploads changed chunks instead of the full dump each day.

_Compare backup strategies like this on daily.dev before picking one for a growing production database._

### Why shouldn't you gzip a database dump before backing it up with Plakar?

Plakar needs the raw, uncompressed dump so it can split the data into chunks and de-duplicate and compress those chunks internally; pre-compressing with gzip would defeat deduplication because compressed output changes unpredictably even when the underlying data barely differs, preventing chunk matches across backups.

_Track tool-specific gotchas like this on daily.dev when adopting a new backup workflow._

### Why can shell redirection with > or tee cause data loss when writing a database backup file?

Redirecting output with the shell's > operator, or using tee, immediately truncates the destination file before the pipeline even starts producing data, so if the backup command fails partway through, the previous working backup gets overwritten with a partial or empty file. The fix is writing to a temporary file first, then atomically moving it into place with mv once the backup completes successfully.

_Save patterns like this atomic-write fix on daily.dev while hardening backup scripts._

## Community discussion

Top comments from developers on daily.dev.

**@fahimahammed** · 0 upvotes

> ![GIF](https://static.klipy.com/ii/4e7bea9f7a3371424e6c16ebc93252fe/d0/24/0OkGR1vsIqWxf5lY3.gif)

## Similar posts on daily.dev

- [Portabase: A Lightweight Self-Hosted Database Backup Solution](https://daily.dev/posts/portabase-a-lightweight-self-hosted-database-backup-solution-5hnbhzxb9) · Noted · 64 upvotes · 2 comments
- [Creating Backup Strategies in Serverless Postgres with Laravel Cloud](https://daily.dev/posts/creating-backup-strategies-in-serverless-postgres-with-laravel-cloud-alidu3kug) · Laravel · 0 upvotes · 0 comments
- [K3s: A Better Way to Deploy a Docker App to a Linux Server](https://daily.dev/posts/k3s-a-better-way-to-deploy-a-docker-app-to-a-linux-server-p8llrvwh7) · Atomic Spin · 16 upvotes · 1 comments
- [How to stream PostgreSQL changes to Amazon S3 with AWS Fargate](https://daily.dev/posts/how-to-stream-postgresql-changes-to-amazon-s3-with-aws-fargate-r9tcxtwht) · AWS Database Blog · 0 upvotes · 0 comments
- [This self-hosted tool replaced a year of backup scripts, and now I barely think about backups at all](https://daily.dev/posts/this-self-hosted-tool-replaced-a-year-of-backup-scripts-and-now-i-barely-think-about-backups-at-all-khstqcpbc) · XDA Developers · 27 upvotes · 2 comments

---

Tags: [#docker](https://daily.dev/tags/docker), [#postgresql](https://daily.dev/tags/postgresql), [#aws-s3](https://daily.dev/tags/aws-s3)

[View this post on daily.dev](https://daily.dev/posts/how-to-back-up-postgresql-in-docker-local-s3-and-plakar-nick-janetakis-l64ac1yno)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Back Up PostgreSQL in Docker (Local, S3, and Plakar) — Nick Janetakis","url":"https://daily.dev/posts/how-to-back-up-postgresql-in-docker-local-s3-and-plakar-nick-janetakis-l64ac1yno","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-back-up-postgresql-in-docker-local-s3-and-plakar-nick-janetakis-l64ac1yno"},"datePublished":"2026-07-21T11:09:58.019Z","dateModified":"2026-09-14T06:52:22.328Z","description":"A comprehensive guide to backing up PostgreSQL databases running in Docker, covering three approaches: local filesystem, AWS S3, and using Plakar (an open...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/0c35e0554e1f53383a8a8eb913788d3b?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/0c35e0554e1f53383a8a8eb913788d3b?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Nick Janetakis","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Nick Janetakis","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/05b22e1c43b541059edfaba1ccc944e6","url":"https://daily.dev/sources/nickjanetakis"},"commentCount":2,"discussionUrl":"https://daily.dev/posts/how-to-back-up-postgresql-in-docker-local-s3-and-plakar-nick-janetakis-l64ac1yno","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":24},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":2}],"keywords":"docker,postgresql,aws-s3","timeRequired":"PT44M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Nick Janetakis","item":"https://daily.dev/sources/nickjanetakis"},{"@type":"ListItem","position":3,"name":"How to Back Up PostgreSQL in Docker (Local, S3, and Plakar) — Nick Janetakis"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-to-back-up-postgresql-in-docker-local-s3-and-plakar-nick-janetakis-l64ac1yno","comment":[{"@type":"Comment","text":"","datePublished":"2026-07-30T04:24:24.594Z","url":"https://daily.dev/posts/L64Ac1YNO#c-cuEF8JJ5i","author":{"@type":"Person","name":"Fahim Ahammed Firoz","url":"https://daily.dev/fahimahammed","image":"https://lh3.googleusercontent.com/a/ACg8ocLPDnjeV4QsaVwi1lXMBgMAKbog9I4fgMTTJnHRKE-Uc1NmSJY0=s96-c"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-back-up-postgresql-in-docker-local-s3-and-plakar-nick-janetakis-l64ac1yno#faq","mainEntity":[{"@type":"Question","name":"How much can deduplicated backups with Plakar reduce S3 data transfer compared to daily full gzipped pg_dumpall backups?","acceptedAnswer":{"@type":"Answer","text":"For a 10 GB database growing about 1% to 2% daily over a year, plain daily gzipped dumps sent to S3 total roughly 12.5 TB transferred, while Plakar's deduplication reduces that to about 64.55 GB transferred over the same year, because Plakar only uploads changed chunks instead of the full dump each day. Compare backup strategies like this on daily.dev before picking one for a growing production database."}},{"@type":"Question","name":"Why shouldn't you gzip a database dump before backing it up with Plakar?","acceptedAnswer":{"@type":"Answer","text":"Plakar needs the raw, uncompressed dump so it can split the data into chunks and de-duplicate and compress those chunks internally; pre-compressing with gzip would defeat deduplication because compressed output changes unpredictably even when the underlying data barely differs, preventing chunk matches across backups. Track tool-specific gotchas like this on daily.dev when adopting a new backup workflow."}},{"@type":"Question","name":"Why can shell redirection with > or tee cause data loss when writing a database backup file?","acceptedAnswer":{"@type":"Answer","text":"Redirecting output with the shell's > operator, or using tee, immediately truncates the destination file before the pipeline even starts producing data, so if the backup command fails partway through, the previous working backup gets overwritten with a partial or empty file. The fix is writing to a temporary file first, then atomically moving it into place with mv once the backup completes successfully. Save patterns like this atomic-write fix on daily.dev while hardening backup scripts."}}]}
```

