From ef76fb8fec8c716626754f1595462ed452819e5a Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Sun, 22 Nov 2026 13:56:25 +0100 Subject: [PATCH 1/3] fix(profiles): gitea profile : Enable the DB dump timer after installing gitea The timer was enabled before the snap install, so a first run could fire while gitea was not installed yet. Co-Authored-By: Claude Opus 5.5 --- profiles/applications/app-gitea.profile.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/profiles/applications/app-gitea.profile.yaml b/profiles/applications/app-gitea.profile.yaml index c544cf5..9e038f6 100644 --- a/profiles/applications/app-gitea.profile.yaml +++ b/profiles/applications/app-gitea.profile.yaml @@ -53,7 +53,8 @@ config: WantedBy=timers.target runcmd: - - systemctl daemon-reload - - systemctl enable --now gitea-db-dump.timer # Install gitea - [ snap, install, gitea ] + # Enable the DB dump timer once gitea is installed + - systemctl daemon-reload + - systemctl enable --now gitea-db-dump.timer -- 2.43.0 From b8b847fe68533b27b49df7f8389c2a6244692048 Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Sun, 22 Nov 2026 13:58:02 +0100 Subject: [PATCH 2/3] refactor(profiles): gitea profile : Use explicit variable names in the DB dump script Co-Authored-By: Claude Opus 5.5 --- profiles/applications/app-gitea.profile.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/profiles/applications/app-gitea.profile.yaml b/profiles/applications/app-gitea.profile.yaml index 9e038f6..73aede5 100644 --- a/profiles/applications/app-gitea.profile.yaml +++ b/profiles/applications/app-gitea.profile.yaml @@ -26,12 +26,12 @@ config: content: | #!/bin/sh set -eu - D=/var/snap/gitea/common/dump - mkdir -p "$D" - F="$D/gitea-db-$(date +%Y%m%d-%H%M).tar" - /snap/bin/gitea dump --skip-repository --skip-lfs-data --skip-attachment-data --skip-package-data --skip-log --skip-custom-dir --skip-index --type tar --file "$F.tmp" - mv "$F.tmp" "$F" - ls -1t "$D"/gitea-db-*.tar | tail -n +25 | xargs -r rm -f -- + DIRECTORY=/var/snap/gitea/common/dump + mkdir -p "${DIRECTORY}" + FILE="${DIRECTORY}/gitea-db-$(date +%Y%m%d-%H%M).tar" + /snap/bin/gitea dump --skip-repository --skip-lfs-data --skip-attachment-data --skip-package-data --skip-log --skip-custom-dir --skip-index --type tar --file "${FILE}.tmp" + mv "${FILE}.tmp" "${FILE}" + ls -1t "${DIRECTORY}"/gitea-db-*.tar | tail -n +25 | xargs -r rm -f -- - path: /etc/systemd/system/gitea-db-dump.service content: | [Unit] -- 2.43.0 From 8f5255f36c695a95502f6e90a8a1be01d2241c75 Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Sun, 22 Nov 2026 13:57:35 +0100 Subject: [PATCH 3/3] feat(profiles): nextcloud profile : Add DB dump script and systemd timers Add a script to dump the DB in the volume dir so DB dumps can be backed up alongside data files, like the gitea profile. The DB is much bigger than gitea's (~216 MB of SQL): the dump runs every 4 hours and the last 24 hours are kept. The dump is plain SQL, not gzipped, so that restic deduplicates between dumps: measured, a gzipped dump adds ~67 MB to the repository each time, a plain one ~5 MB. The dump goes through a pipe: the snap's AppArmor profile prevents nextcloud.mysqldump from writing to a redirected file. --single-transaction gives a consistent dump without locking the tables. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018inUJhddwLWVwYhGB8t6RP --- .../applications/app-nextcloud.profile.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/profiles/applications/app-nextcloud.profile.yaml b/profiles/applications/app-nextcloud.profile.yaml index 294fa79..e787ea4 100644 --- a/profiles/applications/app-nextcloud.profile.yaml +++ b/profiles/applications/app-nextcloud.profile.yaml @@ -21,6 +21,46 @@ config: shell: /bin/bash sudo: ['ALL=(ALL) NOPASSWD:ALL'] + write_files: + # The dump goes through a pipe: the snap's AppArmor profile prevents + # nextcloud.mysqldump from writing to a redirected file (empty dump). + # Plain SQL, not gzipped, so that restic deduplicates between dumps + # (a gzipped dump is uploaded in full each time). + # Every 4 hours, the last 24 hours are kept here. + - path: /usr/local/bin/nextcloud-db-dump.sh + permissions: '0755' + content: | + #!/bin/bash + set -euo pipefail + DIRECTORY=/var/snap/nextcloud/common/dump + mkdir -p "${DIRECTORY}" + FILE="${DIRECTORY}/nextcloud-db-$(date +%Y%m%d-%H%M).sql" + /snap/bin/nextcloud.mysqldump --single-transaction --skip-lock-tables | cat > "${FILE}.tmp" + mv "${FILE}.tmp" "${FILE}" + ls -1t "${DIRECTORY}"/nextcloud-db-*.sql | tail -n +7 | xargs -r rm -f -- + - path: /etc/systemd/system/nextcloud-db-dump.service + content: | + [Unit] + Description=Dump de la base Nextcloud + + [Service] + Type=oneshot + ExecStart=/usr/local/bin/nextcloud-db-dump.sh + - path: /etc/systemd/system/nextcloud-db-dump.timer + content: | + [Unit] + Description=Dump de la base Nextcloud toutes les 4 heures + + [Timer] + OnCalendar=*-*-* 00/4:30 + Persistent=true + + [Install] + WantedBy=timers.target + runcmd: # Install Nextcloud - [ snap, install, nextcloud ] + # Enable the DB dump timer once Nextcloud is installed + - systemctl daemon-reload + - systemctl enable --now nextcloud-db-dump.timer -- 2.43.0