Skip to content

Commit

Permalink
Finish backups
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Nov 23, 2024
1 parent 80bac3d commit c76c271
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion infrastructure/02-configure/01-user-setup.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Set up non-root user
hosts: all
become: yes # enable sudo
become: yes # escalate to root
vars_prompt:
- name: username
prompt: Enter username
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/02-configure/02-system-setup.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Set up system (timezone, packages, unattended upgrades)
hosts: all
become: yes # enable sudo
become: yes # escalate to root

tasks:
# ==================================
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/02-configure/03-tooling-setup.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Set up tooling (caddy, docker, sqlite3)
hosts: all
become: yes # enable sudo
become: yes # escalate to root

tasks:
# ==================================
Expand Down
4 changes: 3 additions & 1 deletion infrastructure/02-configure/05-backup-setup.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name: Set up backups (sqlite DB to AWS S3)
hosts: all
become: yes # enable sudo
vars:
app_dir: "{{ ansible_user_dir }}/.n8n-shortlink"
app_db: "{{ app_dir }}/n8n-shortlink.sqlite"
aws_data: "{{ lookup('file', 'tf-output-aws.json') | from_json }}"
backup_dir: "{{ app_dir }}/backup"
Expand All @@ -17,6 +17,7 @@
# ==================================

- name: Install required packages
become: yes # escalate to root
apt:
name:
- awscli
Expand Down Expand Up @@ -64,6 +65,7 @@
copy:
dest: "{{ ansible_user_dir }}/.aws/credentials"
content: |
[default]
aws_access_key_id = {{ backup_credentials.access_key }}
aws_secret_access_key = {{ backup_credentials.secret_key }}
mode: "0600"
Expand Down
5 changes: 4 additions & 1 deletion infrastructure/02-configure/backup-list.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

# List sqlite DB backups at AWS S3: ./backup-list.sh
# List sqlite DB backups at AWS S3
: '
~/.n8n-shortlink/backup/backup-list.sh
'

BUCKET_NAME=$(grep bucket_name ~/.aws/config | cut -d '=' -f2 | tr -d ' ')

Expand Down
5 changes: 4 additions & 1 deletion infrastructure/02-configure/backup-restore.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

# Restore a sqlite DB backup from AWS S3: ./backup-restore.sh <backup_name>
# Restore a sqlite DB backup from AWS S3:
: '
~/.n8n-shortlink/backup/backup-restore.sh 2024-11-23-17:24:39+0100.sql.gz.enc
'

if [ $# -eq 0 ]; then
echo -e "Error: No backup name provided.\nUsage: $0 <backup_name>\nExample: $0 2020-01-03-17:34:35+0200.sql.gz.enc"
Expand Down
10 changes: 8 additions & 2 deletions infrastructure/02-configure/backup-run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash

# Back up sqlite DB to AWS S3: ./backup-run.sh
# Intended to be run as a cron job.
# Back up sqlite DB to AWS S3. Intended to be run as a cron job. Example manual run:
: '
APP_DB=~/.n8n-shortlink/n8n-shortlink.sqlite \
BACKUP_DIR=~/.n8n-shortlink/backup \
BACKUP_ENCRYPTION_KEY=~/.n8n-shortlink/backup/n8n-shortlink-backup-encryption.key \
BUCKET_NAME=n8n-shortlink-infra-backup-bucket \
~/.n8n-shortlink/backup/backup-run.sh
'

set -euo pipefail

Expand Down

0 comments on commit c76c271

Please sign in to comment.