aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-10-17 23:26:00 -0700
committerEugene Triguba <hello@eugenetriguba.com>2026-10-17 23:26:00 -0700
commit97c5e0b0ff579ec44ca2b19c9458c44074c6eeba (patch)
tree5a0fa510b972577b7d9d6b96e613646074c9e755
parentAdd preserve modification time to hushlogin (diff)
downloadsite-configs-97c5e0b0ff579ec44ca2b19c9458c44074c6eeba.zip
Add automated backups via restic to backblaze's b2 service
-rw-r--r--README.md15
-rwxr-xr-xbootstrap.sh2
-rw-r--r--roles/restic_backups/tasks/main.yml77
-rw-r--r--roles/restic_backups/vars/main.yml6
-rw-r--r--site.yml8
-rw-r--r--vars/secrets.yml18
6 files changed, 118 insertions, 8 deletions
diff --git a/README.md b/README.md
index ee23258..d0a0ebd 100644
--- a/README.md
+++ b/README.md
@@ -2,19 +2,20 @@
This Ansible playbook sets up my git server at https://git.eugenetriguba.com.
-It is intended to be run against an OpenBSD server. It will then:
+It is intended to be run against an OpenBSD server. It will then setup:
-- Setup a web server with OpenBSD's `httpd`
-- Setup a SSL certificate for the host with OpenBSD's `acme-client` and Let's
+- A web server with OpenBSD's `httpd`
+- A SSL certificate for the host with OpenBSD's `acme-client` and Let's
Encrypt
-- Setup a git user to own the git data
-- Setup cgit as the UI for the git data
+- A git user to own the git data
+- cgit as the UI for the git data
+- Automated backups via `restic` and Backblaze's B2 service
## Usage
If you want to use this playbook for your own git server, you'll want to update
-`inventory/git.yml` to give the details of your own server that you want to run
-against.
+`inventory/git.yml` to give the details of your own server and `site.yml` to
+pass in the variable values that make sense for your use case.
Once that is done, you may run:
diff --git a/bootstrap.sh b/bootstrap.sh
index 6fe4797..55b22ae 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -37,7 +37,7 @@ ensure_ansible_collections_installed() {
run_playbook() {
log_step "Running playbook"
- ansible-playbook --ask-become-pass "$PLAYBOOK" "$@"
+ ansible-playbook --ask-become-pass --ask-vault-pass "$PLAYBOOK" "$@"
log_step "Done!"
}
diff --git a/roles/restic_backups/tasks/main.yml b/roles/restic_backups/tasks/main.yml
new file mode 100644
index 0000000..58ce67c
--- /dev/null
+++ b/roles/restic_backups/tasks/main.yml
@@ -0,0 +1,77 @@
+- name: Check mandatory variables are defined
+ assert:
+ that:
+ - restic_backups_b2_key_id is defined
+ - restic_backups_b2_key_secret is defined
+ - restic_backups_repository is defined
+ - restic_backups_password is defined
+
+- name: Install restic
+ community.general.openbsd_pkg:
+ name: "restic"
+ state: present
+
+- name: Check whether the restic repository exists
+ ansible.builtin.command: restic cat config --no-cache
+ environment: "{{ restic_env }}"
+ register: restic_repo_check
+ changed_when: false
+ # From `restic cat config --help`
+ # > Exit status is 0 if the command was successful.
+ # > Exit status is 1 if there was any error.
+ # > Exit status is 10 if the repository does not exist.
+ # > Exit status is 11 if the repository is already locked.
+ # > Exit status is 12 if the password is incorrect.
+ failed_when: restic_repo_check.rc not in [0, 10]
+ no_log: true
+
+- name: Initialize the restic repository
+ ansible.builtin.command: restic init --no-cache
+ environment: "{{ restic_env }}"
+ when: restic_repo_check.rc == 10
+ no_log: true
+
+- name: Create a 'backup' system user
+ ansible.builtin.user:
+ name: _backup
+ create_home: false
+ shell: /sbin/nologin
+ login_class: daemon
+ # /var/www/git is owned by git:git, so to backup that directory, we need
+ # the backup user to be in the git group.
+ groups: git
+ append: yes
+
+- name: Create restic cache directory
+ ansible.builtin.file:
+ path: "/var/cache/restic"
+ state: directory
+ owner: _backup
+ group: wheel
+ mode: "0750"
+
+- name: Create restic env entries in the crontab
+ ansible.builtin.cron:
+ name: "{{ item.key }}"
+ user: _backup
+ env: yes
+ job: "{{ item.value }}"
+ loop: "{{ restic_env | dict2items }}"
+ no_log: true
+
+- name: Add backup job crontab entry
+ ansible.builtin.cron:
+ name: "backup /var/www/git to backblaze"
+ minute: "0"
+ hour: "3"
+ user: _backup
+ job: "restic backup /var/www/git --tag git"
+
+- name: Add backup pruning job crontab entry
+ ansible.builtin.cron:
+ name: "prune /var/www/git backups in backblaze"
+ minute: "0"
+ hour: "4"
+ weekday: "0"
+ user: _backup
+ job: "restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune"
diff --git a/roles/restic_backups/vars/main.yml b/roles/restic_backups/vars/main.yml
new file mode 100644
index 0000000..40ba77d
--- /dev/null
+++ b/roles/restic_backups/vars/main.yml
@@ -0,0 +1,6 @@
+restic_env:
+ AWS_ACCESS_KEY_ID: "{{ restic_backups_b2_key_id }}"
+ AWS_SECRET_ACCESS_KEY: "{{ restic_backups_b2_key_secret }}"
+ RESTIC_REPOSITORY: "{{ restic_backups_repository }}"
+ RESTIC_PASSWORD: "{{ restic_backups_password }}"
+ RESTIC_CACHE_DIR: "/var/cache/restic"
diff --git a/site.yml b/site.yml
index b857e42..99a5ce8 100644
--- a/site.yml
+++ b/site.yml
@@ -1,6 +1,8 @@
- name: OpenBSD Git Server
hosts: all
become: true
+ vars_files:
+ - vars/secrets.yml
roles:
- role: obsd_httpd
vars:
@@ -18,3 +20,9 @@
- role: obsd_cgit
vars:
obsd_cgit_domain: git.eugenetriguba.com
+ - role: restic_backups
+ vars:
+ restic_backups_b2_key_id: "{{ vault_b2_key_id }}"
+ restic_backups_b2_key_secret: "{{ vault_b2_key_secret }}"
+ restic_backups_repository: "{{ vault_restic_repository }}"
+ restic_backups_password: "{{ vault_restic_password }}"
diff --git a/vars/secrets.yml b/vars/secrets.yml
new file mode 100644
index 0000000..70c12b4
--- /dev/null
+++ b/vars/secrets.yml
@@ -0,0 +1,18 @@
+$ANSIBLE_VAULT;1.1;AES256
+62363336333537333839326539343635333830376133623838353636653433613837383261373563
+6533636438363437323536353939393332326462663663350a633138623236633966316162323336
+66653564356231356666383236663534643962626163353065306162333765643666656231643261
+6266363963613932610a313265343436336366336633323332323635303439613638343163636130
+37356464663235393765306564666362653331303536396536376239383933376533626632633337
+62336632373938333964633663626663663133636533633835333634393335383164633338376162
+34313834356263633661353336383635616164656430346639306234346437323332626264373462
+65646238653635323830393466373935376333313835613938373532383539373765383266343162
+65343638373636663036343963663434633539633830383837636263663365383538656539346430
+63653865636663626666316434323461613166653130333964323930323033656266666166613137
+62646633633737386362303761613132353032616266316264373331333436613533616633386137
+35343435323032313864653535633138373763653730646132366139613461653939386632663833
+33366139363730626438313131353862356231666338303464353161636539386164353730393834
+34656539646366386463646664386338343863633035646463343362383764633432303231343735
+35353763343730313265363130616263616432326639343531323162623734636235356339633563
+65376162333734313765623539396263353363623065376332393666353165396335613934303338
+3034