Skip to content

Check your SEO health in minutes with my SEO by Daniel (me). Ensure correct on page Seo on your site Run a free audit →

Quick search

Easy database backups with docker-compose

A practical guide to deploying automated multi-database backups via Docker Compose using nfrastack/container-db-backup, featuring an interactive environment variable configurator.

Safety 5 min read
Easy database backups with docker-compose

After I nuked my mastodon instance in December of 2023, something that took me 3 months to recover, I decided to implement a backup solution for this worst case scenarios.

Find the configurator at the end of the article.Bookmark this page to find it again in the future.

The Evolution of My Infrastructure

It is 2026 now and decided to update the outdated guide and add a configurator too to help you backup your projects more easier.

In November 2025, I drastically overhauled my deployment stack. If you haven't seen it yet, check out A Production-Ready Laravel Architecture with Traefik and FrankenPHP. It is my safest, most performant stack yet, utilizing Laravel Octane and FrankenPHP.

My most safe and performant architecture. Consult it for an updated insight.

My most safe and performant architecture. Consult it for an updated insight.

But backing up data is only half the battle. You also need to know the exact moment things start going sideways before your customers do.

To bridge that gap, I now pair my infrastructure with my premium New Relic Setup Package. For a single flat price, I completely instrument your stack. This covers #Laravel APM, host metrics, system logs, and Traefik dashboard visibility. I hand over The Foundation Kit runbook so you actually own your monitoring. I actively use this exact setup within my own LaraPlugins directory.

With deep observability taken care of, let's look at the final piece of the puzzle. Securing our persistent data automatically.

Idea

Initially, I wanted an open-source backup tool that met a heavy wishlist:

  • Connect to multiple databases concurrently.
  • Simple, one-click restore functionality.
  • A beautiful web UI to manage tasks.
  • 100% Docker-based.

Finding an open-source tool check-marking every single requirement proved nearly impossible. The UI requirement was the hardest to find.

Software selected

After reducing the requirements to the most important ones, I selected this OSS project called docker-db-backup from Dave Conroy.

💡
Back in April 2026 the tiredofit/db-backup project migrated to a new name and home as nfrastack/container-db-backup at https://github.com/nfrastack/container-db-backup

My original setup bound one container per database. A major recent update completely refactored how it functions. It now introduces native multi-job configurations using prefixed environment variables like DB01_ and DB02_. It can target multiple types of database servers simultaneously. This includes MySQL, PostgreSQL, MongoDB, and Redis. It seamlessly ships dumps to local storage, AWS S3, or Azure.

Developer machines once they start to use docker containers. Photo by Ian Taylor / Unsplash
Developer machines once they start to use docker containers. Photo by Ian Taylor / Unsplash

Production Deployment & Config

Integrating this into a production-ready stack is incredibly straightforward. You simply drop the service into the docker-compose.yml file where your database sits.

Here is how I configure it inside my blog infrastructure under a shared Traefik network proxy setup:

services:
  db_backup:
    container_name: db_backup
    image: nfrastack/container-db-backup:latest
    depends_on:
      - mysql
    volumes:
      - ../path/to/your/backup/folder/:/backup
    environment:
      # Global Container Options
      - DEBUG_MODE=FALSE
      - BACKUP_JOB_CONCURRENCY=2

      # Job 1: Ghost Production MySQL
      - DB01_TYPE=mysql
      - DB01_HOST=ghost_mysql
      - DB01_NAME=${DATABASE__CONNECTION__DATABASE}
      - DB01_USER=root
      - DB01_PASS=${DATABASE__CONNECTION__PASSWORD}
      - DB01_BACKUP_INTERVAL=720      # Every 12 hours (12 * 60)
      - DB01_CLEANUP_TIME=72000       # Keep history for 50 days
      - DB01_CHECKSUM=SHA1
      - DB01_COMPRESSION=GZ
      - DB01_SPLIT_DB=TRUE
    restart: always
    networks:
      - traefik

networks:
  traefik:
    external: true
    name: traefik

Naming of env variables update to reflect the new naming convention.

If you need different configs or databases, feel free to check them here https://github.com/nfrastack/container-db-backup (updated link from 2026 onward)

Offsite Strategy Note: Currently, files are stored locally in a parent relative directory. This design allows a secondary agent on my Unraid home server to grab these local files. It replicates them safely offsite to a Microsoft OneDrive account to maximize that 6 TB Family Plan quota.
As of recently I also opted to mount an external service as a local folder on my server and opted to put my folders in there directly without needing another server or using the Microsoft services. if you want to see how i done it please subscribe it give me a strong signal this article is actually useful to people not just me

Finally, in my config, I back files in a directory relative to the parent folder.

I do not recommend keeping the on server backup folder long term. a better strategy is to use the native s3 integration of the service or mount external filesystem and point the path to there. Keeping the backups on the same servers can incur disk storage space exaustion and without proper monitoring can bring down your services. if you want to ensure something like that never happens feel free to hire me for putting up a monitoring system for your company while you focus on the core money making business: https://danielpetrica.com/newrelic/

I hope you found this short article a little helpful. I'll extend it to include more examples and configs once I go through them. If you have any advice or question, please use the comment section.

Database Backup Configurator

Configure multiple database engines dynamically. This tool generates ready-to-use Docker Compose variables and a separate .env file to keep your production credentials clean and structured.

Global Settings

Backup Concurrency
Debug ModeFALSETRUE
System Timezone (TZ)

Database Backup Jobs ({{ jobs.length }})

+ Add Database
DATABASE JOB {{ String(index + 1).padStart(2, '0') }} Remove Job
Database TypeMariaDB / MySQLPostgreSQLRedisMongoDBMicrosoft SQLSQLite3
Connection Host
Database User
Database Name Var
$
Database Pass Var
$
Value in .env File
Interval (Minutes)
Cleanup (Minutes)
CompressionZSTD (Recommended)GZIP (GZ)BZIP2 (BZ)XZIP (XZ)None
docker-compose.yml .env file
Copied to clipboardCopy config
{{ activeTab === 'yaml' ? generatedYaml : generatedEnv }}
{{ activeTab === 'yaml' ? generatedYaml : generatedEnv }}

Related articles

More posts on similar topics you might enjoy.

All articles

Get my updates in your inbox

Register to be the first to receive my new articles on Laravel, DevOps, and more.

Subscribe to the newsletter

One email when new articles are published. No spam, unsubscribe anytime.

Protected by Mailcoach. Double opt-in may apply.