Guest mode. You can read posts without signing up. Comments, ratings, job contacts and your own posts open after you sign up and accept the rules. What is Kommit →

Редакция КоммитРедакция портала
commit 0d894e9 · 19 days ago

Infrastructure: 3-2-1 backups in practice with restic

🌐 Machine-translated from Russian. Show original

In this part:

3-2-1 rule#

  • 3 copies of data (working + 2 backup);
  • on 2 different media or systems;
  • 1 copy — outside the office or server.

Add another rule to this: a backup that has never been restored does not count.

Why restic#

restic — a free backup utility:

  • encrypts data before sending — the storage does not need to be trusted;
  • deduplicates: stores only modified blocks, daily copies take up little space;
  • can store copies on a local disk, via SFTP, in S3-compatible storage, and others.
sudo apt install restic

First repository#

export RESTIC_REPOSITORY=sftp:backup@nas.local:/backups/srv1
export RESTIC_PASSWORD_FILE=/root/.restic-pass   # пароль в файле с правами 600
restic init

⚠️ Lose your password — lose backups. Store it in the password manager and sealed off the server.

Backup#

restic backup /etc /srv /var/backups/db --exclude-caches
restic snapshots          # список копий

Copy databases by dumping, not files on the fly: first pg_dump / mysqldump in /var/backups/db, then restic.

Retention policy#

restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune

A week of daily copies, a month of weekly copies, and a year of monthly copies are a reasonable start.

Automation#

Script /usr/local/bin/backup.sh:

#!/usr/bin/env bash
set -euo pipefail
export RESTIC_REPOSITORY=sftp:backup@nas.local:/backups/srv1
export RESTIC_PASSWORD_FILE=/root/.restic-pass
pg_dump -Fc -U postgres app > /var/backups/db/app.dump
restic backup /etc /srv /var/backups/db --exclude-caches
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
restic check --read-data-subset=5%

And cron: 30 2 * * * root /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1.

For the "out of office" copy, add a second repository in the cloud S3 storage and run the same script with another RESTIC_REPOSITORY.

Recovery check#

Once a month, according to the calendar:

restic restore latest --target /tmp/restore-test --include /srv/app

Make sure the files open and the database dump is restored to the test base. Mark the check date — it's also worth monitoring that the backup was done today.

Comments 00 участников · 0 гостей🔒 Rate and discuss after signing up

Comments · 0

No comments yet.Sign in to comment, rate and see all comments.