82
submitted 1 year ago by [email protected] to c/[email protected]

I just started getting into self hosting using docker compose and I wonder about possible backup solutions. I only have to safe my docker config so far, but I want host files as well. What software and hardware are you using for backup?

you are viewing a single comment's thread
view the rest of the comments
[-] [email protected] 4 points 1 year ago

I doubt your using NixOS so this config might seem useless but at its core it is a simple systemd timer service and bash scripting.

To convert this to another OS you will use cron to call the script at the time you want. Copy the part between script="" and then change out variables like the location of where docker-compose is stored since its different on NixOS.

Let me explain the script. We start out by defining the backupDate variable, this will be the name of the zip file. As of now that variable would be 2023-07-12. We then go to each folder with a docker-compose.yml file and take it down. You could also replace down with stop if you don't plan on updating each night like I do. I use rclone to connect to Dropbox but rclone supports many providers so check it out and see if it has the one you need. Lastly I use rclone to connect to my Dropbox and delete anything older than 7 days in the backup folder. If you end up going my route and get stuck let me know and I can help out. Good luck.

systemd = {
      timers.docker-backup = {
        wantedBy = [ "timers.target" ];
        partOf = [ "docker-backup.service" ];
        timerConfig.OnCalendar= "*-*-* 3:30:00";
      };
      services.docker-backup = {
        serviceConfig.Type = "oneshot";
        serviceConfig.User = "root";
        script = ''
        backupDate=$(date  +'%F')
        cd /docker/apps/rss
        ${pkgs.docker-compose}/bin/docker-compose down

        cd /docker/apps/paaster
        ${pkgs.docker-compose}/bin/docker-compose down

        cd /docker/no-backup-apps/nextcloud
        ${pkgs.docker-compose}/bin/docker-compose down

        cd /docker/apps/nginx-proxy-manager
        ${pkgs.docker-compose}/bin/docker-compose down

        cd /docker/backups/
        ${pkgs.zip}/bin/zip -r server-backup-$backupDate.zip /docker/apps

        cd /docker/apps/nginx-proxy-manager
        ${pkgs.docker-compose}/bin/docker-compose pull
        ${pkgs.docker-compose}/bin/docker-compose up -d

        cd /docker/apps/paaster
        ${pkgs.docker-compose}/bin/docker-compose pull
        ${pkgs.docker-compose}/bin/docker-compose up -d

        cd /docker/apps/rss
        ${pkgs.docker-compose}/bin/docker-compose pull
        ${pkgs.docker-compose}/bin/docker-compose up -d

        cd /docker/no-backup-apps/nextcloud
        ${pkgs.docker-compose}/bin/docker-compose pull
        ${pkgs.docker-compose}/bin/docker-compose up -d

        cd /docker/backups/
        ${pkgs.rclone}/bin/rclone copy server-backup-$backupDate.zip Dropbox:Server-Backup/
        rm server-backup-$backupDate.zip
        ${pkgs.rclone}/bin/rclone delete --min-age 7d Dropbox:Server-Backup/
        '';
      };
    };

[-] [email protected] 1 points 1 year ago

Thanks! I just started setting up NixOS on my laptop and I'm planning to use it for servers next. Saving this for later!

this post was submitted on 12 Jul 2023
82 points (97.7% liked)

Selfhosted

39251 readers
353 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS