From 481d797c7277c74f2464edfad18312ebbcd47175 Mon Sep 17 00:00:00 2001 From: Blallo Date: Sun, 18 Nov 2018 10:31:35 +0100 Subject: [PATCH] Init and added backup stuff for mastodon --- README.md | 3 +++ mastodon/README.md | 25 +++++++++++++++++++++++++ mastodon/dobackup.sh | 5 +++++ mastodon/pg_backup_daily.service | 8 ++++++++ mastodon/pg_backup_daily.timer | 9 +++++++++ mastodon/pg_backup_monthly.service | 8 ++++++++ mastodon/pg_backup_monthly.timer | 9 +++++++++ 7 files changed, 67 insertions(+) create mode 100644 README.md create mode 100644 mastodon/README.md create mode 100755 mastodon/dobackup.sh create mode 100644 mastodon/pg_backup_daily.service create mode 100644 mastodon/pg_backup_daily.timer create mode 100644 mastodon/pg_backup_monthly.service create mode 100644 mastodon/pg_backup_monthly.timer diff --git a/README.md b/README.md new file mode 100644 index 0000000..1cb86aa --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# A small set of server-side utilities + +Divided by server. diff --git a/mastodon/README.md b/mastodon/README.md new file mode 100644 index 0000000..0d946aa --- /dev/null +++ b/mastodon/README.md @@ -0,0 +1,25 @@ +# Utilities to keep mastodon instance clean (and hopefully running) + +## Postgres backup + +(All the mastodon installation is in `/home/mastodon/live` running as `mastodon`). + +Create a `/home/mastodon/.bin` directory and place there the backup script (`dobackup.sh`) +Create also: + + - `/home/mastodon/.bu` + - `/home/mastodon/.bu/monthly` + +Then place in (assuming we are on a debian-like distro) `/lib/systemd/system` the following: + + - `pg_backup_daily.service` + - `pg_backup_daily.timer` + - `pg_backup_monthly.service` + - `pg_backup_monthly.timer` + + +And start them (as root): + +``` +$ systemctl enable pg_backup_*.timer +``` diff --git a/mastodon/dobackup.sh b/mastodon/dobackup.sh new file mode 100755 index 0000000..a1bebb1 --- /dev/null +++ b/mastodon/dobackup.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +BUDIR="/home/mastodon/.bu/" + +pg_dump mastodon_production > "${BUDIR}/$(date +%Y%m%d)-mastodon_production.sql" diff --git a/mastodon/pg_backup_daily.service b/mastodon/pg_backup_daily.service new file mode 100644 index 0000000..bf52d76 --- /dev/null +++ b/mastodon/pg_backup_daily.service @@ -0,0 +1,8 @@ +[Unit] +Description=Backup postgres database mastodon_production + +[Service] +Type=oneshot +User=mastodon +Group=mastodon +ExecStart=/home/mastodon/.bin/dobackup.sh diff --git a/mastodon/pg_backup_daily.timer b/mastodon/pg_backup_daily.timer new file mode 100644 index 0000000..5fff3dd --- /dev/null +++ b/mastodon/pg_backup_daily.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Backup postgres database mastodon_production + +[Timer] +OnCalendar=daily +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/mastodon/pg_backup_monthly.service b/mastodon/pg_backup_monthly.service new file mode 100644 index 0000000..37fbc2f --- /dev/null +++ b/mastodon/pg_backup_monthly.service @@ -0,0 +1,8 @@ +[Unit] +Description=Backup postgres database mastodon_production (monthly) + +[Service] +Type=oneshot +User=mastodon +Group=mastodon +ExecStart=/bin/bash -c "mv $(ls -rt /home/mastodon/.bu/*.sql|tail -1) /home/mastodon/.bu/monthly/" diff --git a/mastodon/pg_backup_monthly.timer b/mastodon/pg_backup_monthly.timer new file mode 100644 index 0000000..468ae76 --- /dev/null +++ b/mastodon/pg_backup_monthly.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Backup postgres database mastodon_production (monthly) + +[Timer] +OnCalendar=monthly +Persistent=true + +[Install] +WantedBy=timers.target