diff options
author | Timo Wilken | 2022-12-31 13:28:51 +0100 |
---|---|---|
committer | Timo Wilken | 2022-12-31 13:28:51 +0100 |
commit | 3d331a392742d9db2f811547d122bb60d972da43 (patch) | |
tree | f975bce09ba4e5a35beaec4821faeba79a56efd8 /tw/system/files | |
parent | 336b73fd56ae24f3bd363f43263a671af92240f0 (diff) |
Track system configuration
Diffstat (limited to 'tw/system/files')
-rw-r--r-- | tw/system/files/kitchen-pc.pub | 1 | ||||
-rwxr-xr-x | tw/system/files/nextcloud-backup | 68 | ||||
-rw-r--r-- | tw/system/files/timo.pub | 1 | ||||
-rw-r--r-- | tw/system/files/wilken-laptop.pub | 1 |
4 files changed, 71 insertions, 0 deletions
diff --git a/tw/system/files/kitchen-pc.pub b/tw/system/files/kitchen-pc.pub new file mode 100644 index 00000000..cdf93db9 --- /dev/null +++ b/tw/system/files/kitchen-pc.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDccEJMlKN1EkjIFqzpq2TEVa0q2V5eBEZ25c+sRp5an2AwOYjZ4I0UHgFq3Ro82a7EdZf3KObM7tu1EJBXaxbtp0BWDpJB2NqZELHaShnA5tcuCGGfN7qTn3o3RA3eYYSxeMC319Rt5W4sMckTayQYBt6F491bfJx7N7n4ISVWM/q2/Mss9VrZiF2bP1IVcIfdkTH3iFIMHSD7aQl5UNwPSbgmAfe0qO+c1EMxaYvUIEXOVDfd+NUilotJPOgThKEBT2iIevinGjKeNZIq+N+EVN2Np/3FzSCRQqqIYGSuA/Y62KFfmZXy0XoL1LXcHCU9DaY/afNX6NfQocBxhyIp stephan@stephan-pc diff --git a/tw/system/files/nextcloud-backup b/tw/system/files/nextcloud-backup new file mode 100755 index 00000000..4c533758 --- /dev/null +++ b/tw/system/files/nextcloud-backup @@ -0,0 +1,68 @@ +#!/bin/sh -e +# Nextcloud backup script, to run nightly. +# Documentation on backups: +# https://docs.nextcloud.com/server/latest/admin_manual/maintenance/backup.html +# https://docs.nextcloud.com/server/latest/admin_manual/maintenance/restore.html +# https://git.mdns.eu/nextcloud/passwords/-/wikis/Administrators/Backups + +. /etc/default/nextcloud-backup +: "${DATABASE_PASSWORD:?You must pass the MySQL database password as DATABASE_PASSWORD}" + +php_ini=$1 +backup_dir=/var/backups/nextcloud/$(date -u '+%Y-%m-%d') +nextcloud_dir=/var/www/nextcloud +nextcloud_data_partition=/var/data # mountpoint of the partition containing Nextcloud data dir +nextcloud_data_path=nextcloud # relative to $nextcloud_data_partition +snapshot=$nextcloud_data_partition/tmp-nextcloud-backup + +nc_maintenance () { + # Enable (--on) or disable (--off) Nextcloud's maintenance mode. + sudo -nu httpd php ${php_ini:+-c "$php_ini"} "$nextcloud_dir/occ" maintenance:mode "$@" +} + +# If there is a previous backup, compare against it later (so we don't have to +# transfer every file). +last_backup_dir=$(ls -1d "$(dirname "$backup_dir")"/????-??-?? | LC_ALL=C sort | tail -1) +[ -d "$last_backup_dir" ] || unset last_backup_dir + +# Don't overwrite existing backups. mkdir will fail if $backup_dir exists. +mkdir -m 750 "$backup_dir" + +# Always turn off maintenance mode and clean up the temporary snapshot on exit, +# whether or not the backup succeeded. +cleanup () { + nc_maintenance --off || : + if [ -d "$snapshot" ]; then + btrfs subvolume delete -c "$snapshot" || : + fi +} +trap cleanup EXIT HUP INT TERM # can't trap KILL + +# Turn Nextcloud off temporarily so the data doesn't change during the backup. +nc_maintenance --on + +# Backup the database. This can only be done offline. +mysqldump --single-transaction --default-character-set=utf8mb4 \ + -u nextcloud -p"$DATABASE_PASSWORD" nextcloud > "$backup_dir/nextcloud.sql" + +# These shouldn't be copied while Nextcloud is online. +rsync -AUXHavx ${last_backup_dir+--link-dest="$last_backup_dir"} \ + "$nextcloud_dir/config" "$nextcloud_dir/themes" "$backup_dir" + +# Make sure everything is synced to disk so it's in our snapshot. +btrfs filesystem sync "$nextcloud_data_partition/$nextcloud_data_path" +btrfs subvolume snapshot -r "$nextcloud_data_partition" "$snapshot" + +# At this point, the data directory is in the snapshot, so Nextcloud can be +# turned on again. +nc_maintenance --off + +# --link-dest is brittle (it only hardlinks to the old file if no metadata has +# changed). Reflinks would be better, but rsync doesn't seem to support them. +# We don't need files under preview/, as those are thumbnails from the Previews +# "app" and can be regenerated using `php -f occ preview:pre-generate`. +rsync -AUXHavx --exclude='appdata_*/preview' --exclude='appdata_*/passwords/*Cache' \ + ${last_backup_dir+--link-dest="$last_backup_dir/data"} \ + "$snapshot/$nextcloud_data_path/" "$backup_dir/data" +# Make sure everything is written out to the backup disk before we exit. +btrfs filesystem sync "$backup_dir" diff --git a/tw/system/files/timo.pub b/tw/system/files/timo.pub new file mode 100644 index 00000000..38012eb3 --- /dev/null +++ b/tw/system/files/timo.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDGNBJNlMWGWuPYkW3nGqK078cRvsGArizQa1Aco8SRGWjabSoeazk4IjYW80dx+FJvPgXowBXmXsctB35kQfw85h1iNOkkroZKBSwFj/kWrNvW7g+cneMLyLIy2Q+1X3ths6m++L1elNryOLdvNZtCB4cYbD22IIi65dtzXK2m3MXbEucXHyTivcRWDxg0HSy3fArJVkW2vst5DBC5zci/Uf8ZnNzyObE5h9IlDARw1VGmDo6Bw25zJMYGIYb+l629mU9dlO1x39JGe/+/l+iJTLfUGbiOvZ6uKMt7c04WBsYF8jFitnKU2Nhfa820p+bSBJYsW5QyQZWG12R36qT timo.21.wilken@gmail.com diff --git a/tw/system/files/wilken-laptop.pub b/tw/system/files/wilken-laptop.pub new file mode 100644 index 00000000..dafd007b --- /dev/null +++ b/tw/system/files/wilken-laptop.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8bnrC257jNnrOo8ItOBB4uUDk/sq+C399MxSNewsbhVVHJ7W531mgLKJcX+Y34nXIyMxq10xJWlvMjw6IlE7fu2V2AOh9QGoYJeu9FkUB5DY74ynGmdrxKDRyQue3CKkNYIxH1OzKJHCFxDPpVytTKPqT1BAGAMOrQiC9nZE0TMYWH1V1YBIQrCYFPAyWzBueTAIUyLXbgfz5GBJq05pgQFI0wOEEKnkAIYc7htd/rGb0xIhcI/X4r3CdXPLwZzxQE/eO3MBClMFpx+QpV9tLeOLOcH9yubk13XUR6dpY/bzhMk2X3teqBUNLliCmIf1jv28qANwJf0J9OxfQQA3B wilken@wilken-laptop |