Lädt...

🔧 4 Easy Ways to Backup Docker Volumes


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

If you are using Docker for anything more than just playing around, you are likely using volumes. Volumes are great, but its easy to f*ck something up and lose data. Don't get caught with your pants down, let's go over some ways to backup your Docker volumes!

Backup Docker Volumes

Application Specific

You're going to hate me for this one, but the best way is to not backup Docker volumes. Instead, backup only the data you need, with the tools you're already using.

If you are running Postgres, you can simply backup your database using the pg_dump command. If you are running mongodb, you can use the mongodump command. These commands will usually give you a lot more control over what you're backing up and can even give you some consistency guarantees that a normal backup won't. If you can, use the right tool for the job!

There are also existing container solutions that wrap tools like pg_dump that make it a bit easier. For example docker-pg-backup by Kartoza.

Creating a backup can be as simple as running a single command:

docker run --name="backups"  --link db:db -v `pwd`/backups:/backups  -d kartoza/pg-backup:$POSTGRES_MAJOR_VERSION-$POSTGIS_MAJOR_VERSION.${POSTGIS_MINOR_RELEASE}

Local Backup

Next is something that a lot of people would not consider a backup, but its good enough if you do some local development and don't need a super robust solution.

If your volume is named my-data, you can copy everything to a new volume called my-data-backup:

docker volume create --name my-data-backup

docker container run --rm -it \
           -v my-data:/from \
           -v my-data-backup:/to \
           ubuntu bash -c "cd /from ; cp -av . /to"

This will create a new volume with the same data as the original. You can then use this new volume as a backup! You might have to change the /from and /to paths depending on what you're backing up.

Remember, this will not protect you from a catastrophic event like your server burning down 🤖🔥.

Hosting Provider

If you use a modern PaaS provider like Sliplane or Render, you can simply use the backup feature of them. This is great if you dont want to worry about managing a backup solution, but is potentially a single point of failure and can cost extra.

Sliplane for example offers free volume backups for production servers, with no limit on the size of the volumes.

Disclaimer: I'm the co-founder, so I obviously think this is good 😆

Sliplane Backups

Upload to S3 with Offen

Offen is a self-hosted backup solution that can backup to a variety of different cloud providers, including S3. It can backup Docker volumes with a simple command:

docker run --rm \
  -v data:/backup/data \
  --env AWS_ACCESS_KEY_ID="<xxx>" \
  --env AWS_SECRET_ACCESS_KEY="<xxx>" \
  --env AWS_S3_BUCKET_NAME="<xxx>" \
  --entrypoint backup \
  offen/docker-volume-backup:v2

Offen is pretty awesome, we even use it at Sliplane to backup volumes. They have great documentation with a bunch of examples and support for a variety of different cloud providers. I would suggest simply backing it up to S3. Make sure to also use the client side encryption to keep your data safe!

The configuration documentation is here.

Conclusion

There you have it! 5 ways to backup your Docker volumes. Use the one that makes the most sense for you and your use case. If you have any other great solutions, please share them in the comments below!

Thanks for reading, and happy backing up!

Cheers, Jonas
Co-Founder of sliplane.io

...

🔧 4 Easy Ways to Backup Docker Volumes


📈 46.53 Punkte
🔧 Programmierung

🔧 Concepts know about Storage Persistent Volumes, Logical Volumes, Partitioning disks in Linux


📈 33.62 Punkte
🔧 Programmierung

🔧 🚀 EBS Volumes for EC2: Should You Use Multiple Small Volumes or One Large Volume? 💡


📈 33.62 Punkte
🔧 Programmierung

🔧 Docker Volumes and Persistence: A Comprehensive Guide-Docker day 3


📈 31.3 Punkte
🔧 Programmierung

🐧 Managing Docker Volumes Using Docker Compose


📈 31.3 Punkte
🐧 Linux Tipps

🔧 How to Hide/Unhide Drives or Volumes in Windows 11 PC? 5 Effective Ways!


📈 24.32 Punkte
🔧 Programmierung

🔧 Docker Volumes


📈 24.05 Punkte
🔧 Programmierung

🔧 Volumes em Docker


📈 24.05 Punkte
🔧 Programmierung

🔧 Day 21 of 100 Days of Cloud: Mastering Docker Volumes for Data Persistence


📈 24.05 Punkte
🔧 Programmierung

🔧 A Complete Guide to Docker: Images, Containers, Networking, and Volumes


📈 24.05 Punkte
🔧 Programmierung

🐧 Chapter 5: Docker Volumes and Data Persistence


📈 24.05 Punkte
🐧 Linux Tipps

🔧 How to locate data volumes in Docker Desktop?


📈 24.05 Punkte
🔧 Programmierung

🔧 How to Manage and Migrate Docker Volumes for PostgreSQL


📈 24.05 Punkte
🔧 Programmierung

🔧 How to locate data volumes in Docker Desktop?


📈 24.05 Punkte
🔧 Programmierung

🔧 Docker Volumes


📈 24.05 Punkte
🔧 Programmierung

🔧 Everything about Docker volumes


📈 24.05 Punkte
🔧 Programmierung

🔧 Docker Volumes vs. Bind Mounts: Choosing the Right Storage for Your Containers.


📈 24.05 Punkte
🔧 Programmierung

🔧 Day 5: Mastering Docker Volumes and Data Persistence


📈 24.05 Punkte
🔧 Programmierung

🔧 Docker Volumes vs. Bind Mounts: Choosing the Right Storage for Your Containers.


📈 24.05 Punkte
🔧 Programmierung

🐧 Docker-Container-Volumes verstehen und verwalten


📈 24.05 Punkte
🐧 Server

🔧 Managing Data with Docker Compose Volumes: Best Practices for Persistence and Sharing


📈 24.05 Punkte
🔧 Programmierung

🐧 How are Volumes Defined in Docker Compose YAML?


📈 24.05 Punkte
🐧 Linux Tipps

🔧 Bind Mounts vs Volumes: Which Docker Data Management Solution is Right for You?


📈 24.05 Punkte
🔧 Programmierung

🐧 How to Mount Docker Volumes


📈 24.05 Punkte
🐧 Linux Tipps

🔧 Mastering Docker Volumes: Best Practices for Persistent Data Management in Containers


📈 24.05 Punkte
🔧 Programmierung

🐧 Clean Up Docker Remove Old Images, Containers, and Volumes


📈 24.05 Punkte
🐧 Linux Tipps

🔧 Day 7: Docker Volumes


📈 24.05 Punkte
🔧 Programmierung

🔧 Dive into the world of Docker volumes: A beginner's guide


📈 24.05 Punkte
🔧 Programmierung

🔧 No one likes losing data! Today you can learn how to persist data with Docker Volumes :)


📈 24.05 Punkte
🔧 Programmierung

🔧 🐳 Docker Bind Mounts vs Volumes: What's the Difference?


📈 24.05 Punkte
🔧 Programmierung

🐧 Mounting an NFS directly to /var/lib/docker/volumes on Swarm nodes


📈 24.05 Punkte
🐧 Linux Tipps

🔧 Working with Docker Volumes


📈 24.05 Punkte
🔧 Programmierung

🔧 Managing Data in Docker: Understanding Volumes for Persistence


📈 24.05 Punkte
🔧 Programmierung

🔧 How to Upload and Download Files to Docker Volumes


📈 24.05 Punkte
🔧 Programmierung