4 min read

Call for Backup

Call for Backup

UPDATE: I noticed after posting this that I can use autorestic exec to run restic commands using the autorestic configs so I don't have to exec stuff first.

After getting my main docker config setup wiped out, current suspect is portainer but no confirmation as of yet, I decided I need to get a little more motivated on backup solutions. I didn't realize how cheap backup solutions have become so I was avoiding offsite options, I recently posted about others backup situations and someone mentioned Backblaze and that they pay less than a few dollars a month. I figure a few dollars a month is worth my time and piece of mind when it comes time to run a restore.

The current setup is going to be MinIO and AutoRestic. I know I said Backblaze earlier, but I want to get to a point that backups are running smooth with this setup and then I will ADD, this is the keyword here, Backblaze to the setup. This will give me one backup that's locally available and one backup offsite. I know that's not enough by the standards put out there but I am just running a homelab so I am happy with this setup.

On to configuration. First we will setup MinIO, for this we just need to decide where we are going to store the files. I have NFS mounts setup from my unraid server so will be storing it in Backups, which is mounted to /opt/Backups. The compose for MinIO will therefor be the following. Whichever port you map 9000 to is the one where you will send your backup requests and 9090, which as you can see is set in the command line, is where you will access the webui.

  minio:
    image: minio/minio:latest
    container_name: minio
    volumes:
      - /opt/Backups/minio:/data
    ports:
      - "9091:9000"
      - "9090:9090"
    environment:
      MINIO_ROOT_USER: miniouser
      MINIO_ROOT_PASSWORD: miniopassword
    command: server --console-address ":9090" /data

Now onto AutoRestic. This one really tripped me up, all the documentation I found online isn't very detailed which I am guessing is because people are coming from just restic so this is easy automation for them. For those starting fresh there is an extra step that is only covered in the restic docs, but before we get to that let's start with AutoRestic setup. Below you can find the config file I built for my setup.

version: 2

global:
  forget:
    keep-last: 5 # always keep at least 5 snapshots

locations:
  home:
    from: /opt/config
    to: minio
    cron: '0 3 * * 0' # Every Sunday at 3:00

  important:
    from: /opt/compose
    to: minio
    cron: '0 3 * * 0' # Every Sunday at 3:00

backends:
  remote:
    type: b2
    path: 'myBucket:backup/home'
    env:
      B2_ACCOUNT_ID: account_id
      B2_ACCOUNT_KEY: account_key

  minio:
    type: s3
    # path: s3.amazonaws.com/bucket_name
    # Minio
    path: http://minio:9000/autorestic
    key: key #key used to encrypt data
    env:
      AWS_ACCESS_KEY_ID: access_key
      AWS_SECRET_ACCESS_KEY: secret_key

  hdd:
    type: local
    path: /mnt/my_external_storage

Alright let's run through my config real quick. Global applies to all backups you run, I am doing weekly backups and only keeping the last 5. Next is the locations you want backed up and the added cron option with how often to run the backup, as mentioned before, just going to backup my configs and compose folder. Next is backends or the target backup locations, b2 is in the default config and because I eventually plan to use it I decided to just keep it there. Next is the minio setup, the key mentioned there is the one you specify during the init which I will explain next and then the two keys that you setup in minio ui. Hdd is again part of stock config, I'll probably delete that as I won't be using it. Next we will do the init I have mentioned a few times, first lets add this to our compose file, but don't start the container yet.

  autorestic:
    image: cupcakearmy/autorestic
    container_name: autorestic
    volumes:
      - /opt:/opt:ro
      - /opt/config/autorestic/.autorestic.yaml:/data/.autorestic.yaml
    command: autorestic backup -va -c /data/.autorestic.yaml

Next we need to replace the command with sleep 1000, and then we are going to exec into the container to init the storage using the following command. Without this command I wasn't able to get my auto restic backups to run, and now they are running correctly. Run the following command and then you should get a success message that your bucket is setup. Just a note my bucket name is autorestic as you can see in my config above so use whatever you want just make sure your config aligns.

autorestic -c /data/.autorestic.yaml exec -b minio init

Once that's done you can go back into your compose, set the command back to what it was above and you are good to go. Sunday hasn't passed for me since I set this up so I haven't confirmed that the cron piece is working but I will be sure to come back here and update this when I do check.

UPDATE:
If all you're looking for is simple, your best bet is to setup a cron job on your host system that runs <docker compose up -d autorestic>. If you want something prettier and more robust sit tight cause my next post will cover that. As a side note the compression has been great for me, the data I am backing up is 16GB and the bucket size after backup is about 7GB.