Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

NodeBB

  1. Home
  2. Selfhosted
  3. Docker Backup Stratagy

Docker Backup Stratagy

Scheduled Pinned Locked Moved Selfhosted
selfhosted
28 Posts 20 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N [email protected]

    Hello Self-Hosters,

    What is the best practice for backing up data from docker as a self-hoster looking for ease of maintenance and foolproof backups? (pick only one 😄 )

    Assume directories with user data are mapped to a NAS share via NFS and backups are handled separately.

    My bigger concern here is how do you handle all the other stuff that is stored locally on the server, like caches, databases, etc. The backup target will eventually be the NAS and then from there it'll be double-backed up to externals.

    1. Is it better to run #cp /var/lib/docker/volumes/* /backupLocation every once in a while, or is it preferable to define mountpoints for everything inside of /home/user/Containers and then use a script to sync it to wherever you keep backups? What pros and cons have you seen or experienced with these approaches?

    2. How do you test your backups? I'm thinking about digging up an old PC to use to test backups. I assume I can just edit the ip addresses in the docker compose, mount my NFS dirs, and failover to see if it runs.

    3. I started documenting my system in my notes and making a checklist for what I need to backup and where it's stored. Currently trying to figure out if I want to move some directories for consistency. Can I just do docker-compose down edit the mountpoints in docker-compose.yml and run docker-compose up to get a working system?

    G This user is from outside of this forum
    G This user is from outside of this forum
    [email protected]
    wrote last edited by
    #19

    You want your docker container’s persistent data mounted to real locations. I use the volumes for non-persistent stuff.

    You want your real locations to have a file system that can snapshot (ZFS, BTRFS).

    Then you can dump the superior Postgres databases and for all other databases and data, you stop the containers, snapshot, start the containers (limits downtime!), and then back up that snapshot. Thanks to snapshot, you don’t need to wait until the backup is done to bring the containers back up for data consistency. For backup I use restic, it does seem to work well, and has self-check functions so that’s nice. I chose restic instead of just sending snapshots because of its coupled encryption and checks, which allow for reliable data integrity on unreliable mediums (anyone, even giant providers, could blackhole bits of your backup!). I copy over the restic binary that made the backup using encrypted rclone, the encryption there prevents anyone (the baddies? Idk who’d target me but it doesn’t matter now!) from mucking with the binary if you did need that exact version to restore from for some reason.

    Note I do not dump SQL or the like, they’re offline and get snapshotted in a stable state. The SQL dump scene was nasty, esp compared to Postgres’ amazingly straightforward way (while running!). I didn’t bother figuring out SQL dump or restore.

    All of your containers should have specific users for them, specify the UID/GID so they’re easily recreatable in a restore scenario. (The database containers get their own users too)

    Addendum for the specific users: Make an LXC container run by a specific user and put the docker container in it if the docker container is coded by F tier security peeps and hard requires root. Or use podman, it is competent and can successfully lie to those containers.

    I don’t test my backups because the time to do so is stupid high thanks to my super low internet speeds. I tested restoring specific files with restic when setting it up and now I rely on the integrity checks (2GB check a day) to spot check everything is reliable. I have a local backup as well as a remote, the local is said snapshot used to make the restic remote backup. The snapshot is directly traversable and I don’t need to scrutinize it hard. If I had faster internet, I’d test restoring remote restic once a year probably. For now I try to restore a random file or small directory once a year.

    Hope the rant helps

    N 1 Reply Last reply
    4
    • G [email protected]

      You want your docker container’s persistent data mounted to real locations. I use the volumes for non-persistent stuff.

      You want your real locations to have a file system that can snapshot (ZFS, BTRFS).

      Then you can dump the superior Postgres databases and for all other databases and data, you stop the containers, snapshot, start the containers (limits downtime!), and then back up that snapshot. Thanks to snapshot, you don’t need to wait until the backup is done to bring the containers back up for data consistency. For backup I use restic, it does seem to work well, and has self-check functions so that’s nice. I chose restic instead of just sending snapshots because of its coupled encryption and checks, which allow for reliable data integrity on unreliable mediums (anyone, even giant providers, could blackhole bits of your backup!). I copy over the restic binary that made the backup using encrypted rclone, the encryption there prevents anyone (the baddies? Idk who’d target me but it doesn’t matter now!) from mucking with the binary if you did need that exact version to restore from for some reason.

      Note I do not dump SQL or the like, they’re offline and get snapshotted in a stable state. The SQL dump scene was nasty, esp compared to Postgres’ amazingly straightforward way (while running!). I didn’t bother figuring out SQL dump or restore.

      All of your containers should have specific users for them, specify the UID/GID so they’re easily recreatable in a restore scenario. (The database containers get their own users too)

      Addendum for the specific users: Make an LXC container run by a specific user and put the docker container in it if the docker container is coded by F tier security peeps and hard requires root. Or use podman, it is competent and can successfully lie to those containers.

      I don’t test my backups because the time to do so is stupid high thanks to my super low internet speeds. I tested restoring specific files with restic when setting it up and now I rely on the integrity checks (2GB check a day) to spot check everything is reliable. I have a local backup as well as a remote, the local is said snapshot used to make the restic remote backup. The snapshot is directly traversable and I don’t need to scrutinize it hard. If I had faster internet, I’d test restoring remote restic once a year probably. For now I try to restore a random file or small directory once a year.

      Hope the rant helps

      N This user is from outside of this forum
      N This user is from outside of this forum
      [email protected]
      wrote last edited by
      #20

      Interesting username. Are you a fellow student of Internet Comment Etiquette?

      I know at least some of my containers use Postgres. Glad to know I inadvertently might have made it easier on myself. I'll have to look into the users for the db and db containers. I'm a bit lost on that. I know my db has a username and pass I set in the docker compose file and that the process is running with a particular GID UID or whatever. Is that what your talking about?

      G 1 Reply Last reply
      0
      • C [email protected]

        Bind mounts. I've never bothered to figure out named volumes, since I often work with the contents outside Docker. Then I just back up the whole proxmox VM. (Yes I'm aware proxmox supports containers, no I don't plan to convert, that's more time and effort for no meaningful gain to me.)

        You can restore that backup to a new VM. I just make sure it boots and I can access the files. Turn off networking before you boot it so that it doesn't cause conflicts.

        C This user is from outside of this forum
        C This user is from outside of this forum
        [email protected]
        wrote last edited by
        #21

        After getting a NAS to replace my raspberry pi 4 as a home server, I literally just SCPd the bind mounts and docker compose folder, adjusted a few env variables (and found out of a few I needed to add for things like the uid/guid the NAS used as default for the media user I created) and it took maybe 30 minutes total to be back and running. Highly agree with you from experience.

        C 1 Reply Last reply
        0
        • C [email protected]

          After getting a NAS to replace my raspberry pi 4 as a home server, I literally just SCPd the bind mounts and docker compose folder, adjusted a few env variables (and found out of a few I needed to add for things like the uid/guid the NAS used as default for the media user I created) and it took maybe 30 minutes total to be back and running. Highly agree with you from experience.

          C This user is from outside of this forum
          C This user is from outside of this forum
          [email protected]
          wrote last edited by
          #22

          Yup, it works great. I actually did it myself when migrating from a centos to debian host. Worked first try, no issues (except one thing that was already broken but I didn't know because I hadn't accessed it recently). Containers are great for this.

          1 Reply Last reply
          1
          • pory@lemmy.worldP [email protected]

            Everyone I know that actually keeps backups has the same kind of story. It's sad that no matter how many other people talk about keeping backups, it always takes a tragic loss like this to get people to buy hardware/subscriptions.

            N This user is from outside of this forum
            N This user is from outside of this forum
            [email protected]
            wrote last edited by [email protected]
            #23

            Damn, those stories scare me a lot because I can't afford good enough backups right now, so I rely on mirroring via Syncthing what I can and using an USB for my server (fortunately I don't have a lot of personal things). All the family memories are in multiple locations and devices so I don't have the time (nor storage) to backup those lol

            Because of my situation, it takes me some time to save even for second hand things (I just bought a CPU and a new voltage regulator). I'm planning on buying some used HDDs as secondary storage and one as an external. Slowly but surely 😧

            pory@lemmy.worldP 1 Reply Last reply
            0
            • N [email protected]

              Interesting username. Are you a fellow student of Internet Comment Etiquette?

              I know at least some of my containers use Postgres. Glad to know I inadvertently might have made it easier on myself. I'll have to look into the users for the db and db containers. I'm a bit lost on that. I know my db has a username and pass I set in the docker compose file and that the process is running with a particular GID UID or whatever. Is that what your talking about?

              G This user is from outside of this forum
              G This user is from outside of this forum
              [email protected]
              wrote last edited by
              #24

              I do not know of Internet Comment Etiquette, sorry to disappoint! It’s a username that’s humorous to me and fits a core tenant of mine

              Do remember (or put in the .env) the user/pass for your db’s, but they don’t matter much if you know them.

              I’m talking about the process, the ‘user: 6969:6969’ in the docker.compose file. If it’s not there the container runs as the user running docker, and unless you’ve got non-root docker going it’ll run the containers as root. Which could be bad, so head that off if you can! Overall, I’d say it’s a low priority, but a real priority. Some naughty container could do bad things with root privilege and some docker vulnerabilities. I’ve never heard of it that kind of attack in the self hosted community, but as self hosting gains traction I worry a legit container will get an attack slipped in somehow and wreck (prob ransomware) root docker installations.

              First priority is backup - then you can worry about removing root containers (if you haven’t already done so!).

              1 Reply Last reply
              0
              • N [email protected]

                Damn, those stories scare me a lot because I can't afford good enough backups right now, so I rely on mirroring via Syncthing what I can and using an USB for my server (fortunately I don't have a lot of personal things). All the family memories are in multiple locations and devices so I don't have the time (nor storage) to backup those lol

                Because of my situation, it takes me some time to save even for second hand things (I just bought a CPU and a new voltage regulator). I'm planning on buying some used HDDs as secondary storage and one as an external. Slowly but surely 😧

                pory@lemmy.worldP This user is from outside of this forum
                pory@lemmy.worldP This user is from outside of this forum
                [email protected]
                wrote last edited by
                #25

                A second device on site is still infinitely more resilient than just letting it rock. Most use cases where a backup would help can be covered by an occasional one way sync or scheduled copy to a USB drive. Offsite is for catastrophes like your home burning down or flooding.

                1 Reply Last reply
                1
                • G [email protected]

                  I don't know if it's best practice but I mount everything to a specific folder instead of volumes. I also just stop all the containers before a backup instead of database dumping. Then just do an encrypted B2 backup using Restic.

                  So far I had to restore twice in six years of running this system and assuming the folder path is the same the only thing after downloading all the data I had to do was

                  docker-compose up -d
                  
                  D This user is from outside of this forum
                  D This user is from outside of this forum
                  [email protected]
                  wrote last edited by [email protected]
                  #26

                  yeah this is the way. as part of my borgmatic script I bring down all the stacks that have databases, let the backup run, then bring those stacks back up. as long as the containers aren’t running (and as long as the container properly closes itself down, not usually something to be worried about though), any method of data back up should be fine.

                  I do this with quadlets and systemd targets now but before I was doing it with a bunch of docker compose down commands.

                  It is quite convenient for restoration, as you say

                  1 Reply Last reply
                  1
                  • N [email protected]

                    Hello Self-Hosters,

                    What is the best practice for backing up data from docker as a self-hoster looking for ease of maintenance and foolproof backups? (pick only one 😄 )

                    Assume directories with user data are mapped to a NAS share via NFS and backups are handled separately.

                    My bigger concern here is how do you handle all the other stuff that is stored locally on the server, like caches, databases, etc. The backup target will eventually be the NAS and then from there it'll be double-backed up to externals.

                    1. Is it better to run #cp /var/lib/docker/volumes/* /backupLocation every once in a while, or is it preferable to define mountpoints for everything inside of /home/user/Containers and then use a script to sync it to wherever you keep backups? What pros and cons have you seen or experienced with these approaches?

                    2. How do you test your backups? I'm thinking about digging up an old PC to use to test backups. I assume I can just edit the ip addresses in the docker compose, mount my NFS dirs, and failover to see if it runs.

                    3. I started documenting my system in my notes and making a checklist for what I need to backup and where it's stored. Currently trying to figure out if I want to move some directories for consistency. Can I just do docker-compose down edit the mountpoints in docker-compose.yml and run docker-compose up to get a working system?

                    mangopenguin@lemmy.blahaj.zoneM This user is from outside of this forum
                    mangopenguin@lemmy.blahaj.zoneM This user is from outside of this forum
                    [email protected]
                    wrote last edited by [email protected]
                    #27

                    I back up all the directories and docker-compose files using Restic (via Backrest) stored on Backblaze B2, and also the whole Docker LXC via Proxmox's backup function to a local HDD.

                    There's a chance some databases could be backed up in an unusable state, but I keep like 30-50 snapshots going back months, so I figure if the latest one has a bad DB backup, I could go back another day and try that one.

                    I also don't really have irreplaceable data stored in DBs, stuff like Immich has data in a DB that would be annoying to lose, but the photos themselves are just on the filesystem.

                    For testing Restic I pull a backup and just go through and check some of the important files.

                    Proxmox backup is really easy to test, as it just restores the whole LXC with a new ID and IP that I can check.

                    1 Reply Last reply
                    0
                    • dataprolet@lemmy.dbzer0.comD [email protected]

                      While that's an easy solution it makes it impossible or rather difficult to restore single containers and/or files.

                      mangopenguin@lemmy.blahaj.zoneM This user is from outside of this forum
                      mangopenguin@lemmy.blahaj.zoneM This user is from outside of this forum
                      [email protected]
                      wrote last edited by [email protected]
                      #28

                      It's pretty easy, you can browse files in an LXC backup and restore specific parts. For VMs you can just restore the whole VM and copy out what you need.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Login or register to search.
                      Powered by NodeBB Contributors
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups