Browse Source

Implement backup and restore scripts

The usage is pretty simple:

$ ./backup-gitea.sh
...
$ ./retore-gitea.sh <some-timestamp>
...

The timestamps are appended to the compressed backup files.
remove-logs
Andreas Linz 3 years ago
parent
commit
8c07af685c
14 changed files with 109 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +8
    -0
      backup-caddy.sh
  3. +9
    -0
      backup-gitea.sh
  4. +8
    -0
      backup-grafana.sh
  5. +8
    -0
      backup-jupyter.sh
  6. +8
    -0
      backup-prometheus.sh
  7. +10
    -0
      backup-psql.sh
  8. +9
    -0
      restore-caddy.sh
  9. +10
    -0
      restore-gitea.sh
  10. +9
    -0
      restore-grafana.sh
  11. +9
    -0
      restore-jupyter.sh
  12. +9
    -0
      restore-prometheus.sh
  13. +10
    -0
      restore-psql.sh
  14. +1
    -0
      roles/common/tasks/main.yml

+ 1
- 0
.gitignore View File

@ -2,3 +2,4 @@
/*.log
/vault.pass
/*.retry
/backups

+ 8
- 0
backup-caddy.sh View File

@ -0,0 +1,8 @@
#!/bin/bash
set -euo pipefail
timestamp=$(date --iso-8601=seconds)
ssh klingt.vnet "sudo systemctl stop caddy"
ssh klingt.vnet "sudo tar -C /home/caddy -cf - -- certs restic files.klingt.vnet | pixz" > "backups/caddy-files-${timestamp}.tar.xz"
ssh klingt.vnet "sudo systemctl start caddy"

+ 9
- 0
backup-gitea.sh View File

@ -0,0 +1,9 @@
#!/bin/bash
set -euo pipefail
timestamp=$(date --iso-8601=seconds)
ssh klingt.vnet "sudo systemctl stop gitea"
ssh klingt.vnet "sudo tar -C /home/gitea -cf - -- gitea | pixz" > "backups/gitea-files-${timestamp}.tar.xz"
./backup-psql.sh gitea $timestamp
ssh klingt.vnet "sudo systemctl start gitea"

+ 8
- 0
backup-grafana.sh View File

@ -0,0 +1,8 @@
#!/bin/bash
set -euo pipefail
timestamp=$(date --iso-8601=seconds)
ssh klingt.vnet "sudo systemctl stop grafana"
./backup-psql.sh grafana $timestamp
ssh klingt.vnet "sudo systemctl start grafana"

+ 8
- 0
backup-jupyter.sh View File

@ -0,0 +1,8 @@
#!/bin/bash
set -euo pipefail
timestamp=$(date --iso-8601=seconds)
ssh klingt.vnet "sudo systemctl kill jupyter"
ssh klingt.vnet "sudo tar -C /home/jupyter -cf - -- notebooks | pixz" > "backups/jupyter-files-${timestamp}.tar.xz"
ssh klingt.vnet "sudo systemctl start jupyter"

+ 8
- 0
backup-prometheus.sh View File

@ -0,0 +1,8 @@
#!/bin/bash
set -euo pipefail
timestamp=$(date --iso-8601=seconds)
ssh klingt.vnet "sudo systemctl kill prometheus"
ssh klingt.vnet "sudo tar -C /home/prometheus -cf - -- data | pixz" > "backups/prometheus-files-${timestamp}.tar.xz"
ssh klingt.vnet "sudo systemctl start prometheus"

+ 10
- 0
backup-psql.sh View File

@ -0,0 +1,10 @@
#!/bin/bash
set -euo pipefail
database="$1"
timestamp="${2:-$(date --iso-8601=seconds)}"
fname="backups/${database}-psql-${timestamp}.xz"
echo "Creating $fname ..."
ssh klingt.vnet "pg_dump --user=alinz $database --format=custom | pixz" > "$fname"

+ 9
- 0
restore-caddy.sh View File

@ -0,0 +1,9 @@
#!/bin/bash
set -euo pipefail
timestamp="$1"
ssh klingt.vnet "sudo systemctl stop caddy"
cat "backups/caddy-files-${timestamp}.tar.xz" | ssh klingt.vnet "sudo tar -C /home/caddy -xJvf -"
ssh klingt.vnet "sudo systemctl start caddy"

+ 10
- 0
restore-gitea.sh View File

@ -0,0 +1,10 @@
#!/bin/bash
set -euo pipefail
timestamp="$1"
ssh klingt.vnet "sudo systemctl stop gitea"
cat "backups/gitea-files-${timestamp}.tar.xz" | ssh klingt.vnet "sudo tar -C /home/gitea -xJvf -"
./restore-psql.sh gitea $timestamp
ssh klingt.vnet "sudo systemctl start gitea"

+ 9
- 0
restore-grafana.sh View File

@ -0,0 +1,9 @@
#!/bin/bash
set -euo pipefail
timestamp="$1"
ssh klingt.vnet "sudo systemctl stop grafana"
./restore-psql.sh grafana $timestamp
ssh klingt.vnet "sudo systemctl start grafana"

+ 9
- 0
restore-jupyter.sh View File

@ -0,0 +1,9 @@
#!/bin/bash
set -euo pipefail
timestamp="$1"
ssh klingt.vnet "sudo systemctl stop jupyter"
cat "backups/jupyter-files-${timestamp}.tar.xz" | ssh klingt.vnet "sudo tar -C /home/jupyter -xJvf -"
ssh klingt.vnet "sudo systemctl start jupyter"

+ 9
- 0
restore-prometheus.sh View File

@ -0,0 +1,9 @@
#!/bin/bash
set -euo pipefail
timestamp="$1"
ssh klingt.vnet "sudo systemctl stop prometheus"
cat "backups/prometheus-files-${timestamp}.tar.xz" | ssh klingt.vnet "sudo tar -C /home/prometheus -xJvf -"
ssh klingt.vnet "sudo systemctl start prometheus"

+ 10
- 0
restore-psql.sh View File

@ -0,0 +1,10 @@
#!/bin/bash
set -euo pipefail
database="$1"
timestamp="$2"
fname="backups/${database}-psql-${timestamp}.xz"
echo "Restoring $fname ..."
xz --decompress --stdout "$fname" | ssh klingt.vnet "pg_restore --user=alinz --dbname=${database} --clean"

+ 1
- 0
roles/common/tasks/main.yml View File

@ -23,6 +23,7 @@
apt:
package:
- sudo
- pixz
- htop
become: true
- name: Check sudo group

Loading…
Cancel
Save