Backing up databases inside docker containers

November 1, 2021

We recently posted a guide to get up and running with the great backup tool Kopia and received a question asking if it was possible to use the Kopia installation on the host to back up container databases as well.

Absolutely! Just use docker exec and mysqldump to export the database to the host filesystem as a sql file.

The example below is similar to a command that we run as a cron job each night. The name of the container is mariadb, and $MYSQL_ROOT_PASSWORD is an environment variable that exists within the container. The exact command may not work right off the bat on your system, but it should get you most of the way there.

docker exec mariadb sh -c 'mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /root/db/mariadb.sql

Why FTL?

Traditional Host
FTL

Inexpensive Monthly Plan

Our $20/site rate includes all of the features below with no long term commitment, no hidden fees, and no surprise changes. Cancel any time.

High Performance Servers

With AMD EPYC processors, RAID 10 NVMe SSDs, cutting edge software, and a 10 Gbit network connection, there's no need to limit visits, bandwidth, or files.

Fully Managed by Developers

We take care of all the technical stuff so you can focus on your website. And support is always free.

PageSpeed & SEO Optimization

As part of the migration process we work directly on your website to increase performance and ensure SEO best practices.

Reliable Daily Backups

Encrypted snapshots of your files and databases stored in the cloud, plus local redundancy via RAID 10. Our backups are not deleted after a month.

Top Notch Security

Reduce the risk of hacks and downtime with SSL, HSTS, DDoS / bot protection, containerization, secure tunneling, and site-specific Fail2ban filters.

Global Edge Caching & CDN

We leverage Cloudflare's global network of 250 edge nodes in 100+ countries, so you can reach 95% of the world's population within the blink of an eye.

Active Uptime Monitoring

If your website goes down, we'll know before you do. And if a server problem causes uptime to drop below 99.9% in any given month, you won't be charged.

Guaranteed Email Deliverability

Forget about emails not being delivered or ending up in spam folders. We'll set you up with an SMTP server for foolproof email delivery.

Smart Image Optimization

New images are scanned daily and optimized using vips. WordPress sites get our custom vips plugin to greatly improve image processing speed and quality.

Money Back Promise

If you're not satisfied with our service during the first 60 days, we'll refund all payments and help migrate your site to another provider.