Skip to content

Instantly share code, notes, and snippets.

@taking
Last active September 6, 2023 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save taking/c357f8283aac7078a321a9ca8402fb5b to your computer and use it in GitHub Desktop.
Save taking/c357f8283aac7078a321a9ca8402fb5b to your computer and use it in GitHub Desktop.

Minio Install

# .env
DOCKER_ROOT=/volume/1TB_NVME/docker/minio-backup

TZ=Asia/Seoul

# DB
MINIO_ROOT_USER=username
MINIO_ROOT_PASSWORD=password
# docker-compose.yml
version: '2'

services:
  minio:
    image: docker.io/bitnami/minio:2023
    restart: always
    container_name: minio
    env_file: ./.env
    ports:
      - '9000:9000'
      - '9001:9001'
    volumes:
      - './minio_data:/data'

Restic Install

#!/bin/bash

wget $(curl -s https://api.github.com/repos/restic/restic/releases/latest | grep browser_download_url | cut -d\" -f4 | egrep 'linux_amd64')

bunzip2 -d ./restic*.bz2
chmod 755 ./restic*
sudo mv ./restic* /usr/local/bin/restic

image

export AWS_ACCESS_KEY_ID=<YOUR-MINIO-ACCESS-KEY-ID>
export AWS_SECRET_ACCESS_KEY=<YOUR-MINIO-SECRET-ACCESS-KEY>
restic -r s3:http://localhost:9000/restic init

image image image

First Backup

# for root
restic -r s3:http://localhost:9000/restic --verbose backup /volume/1TB_NVME/docker/

image

Second Backup - Snapshot

restic -r s3:http://localhost:9000/restic --verbose snapshots

image

Restore

restic -r s3:http://localhost:9000/restic --verbose restore latest --target /volume/1TB_NVME/docker

Cron

# Secret
mkdir -p /volume/1TB_NVME/.secret
cat <<EOF > /volume/1TB_NVME/.secret/.secret-restic
export AWS_ACCESS_KEY_ID=<YOUR-MINIO-ACCESS-KEY-ID>
export AWS_SECRET_ACCESS_KEY=<YOUR-MINIO-SECRET-ACCESS-KEY>
export RESTIC_REPOSITORY="s3:http://localhost:9000/restic"
export RESTIC_PASSWORD="<YOUR-RESTIC-PASSWORD>"
EOF
chmod 600 /volume/1TB_NVME/.secret
# Cron Shell
mkdir -p /root/cron
cat <<EOF > /root/cron/restic-autobackup
#!/bin/bash
source /volume/1TB_NVME/.secret/.secret-restic
restic --verbose backup /volume/1TB_NVME/docker/
restic backup /volume/1TB_NVME/docker/ --tag taking
restic snapshots
restic stats
EOF
chmod a+x /root/cron/restic-autobackup

image image

# Cron Append
(crontab -l ; echo "0 4 * * * /root/cron/restic-autobackup")| crontab -
# remove snapshots
restic forget --keep-last 1 --prune

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment