summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@parabola.nu>2018-06-22 12:48:27 -0400
committerLuke Shumaker <lukeshu@parabola.nu>2018-10-07 19:33:41 -0400
commit24158f712e9b808366c4f6eeeb125ae3fd1cb942 (patch)
tree314d5ee200d63f0616b711705f08c54bc9612d94
parent2ef982e9ae24a11bdf20224f2d17178700561ce7 (diff)
Add from Parabola: db-cleanup
If you're seeing this in `git blame`, it chose to follow the wrong ancestor of a merge commit.
-rw-r--r--README.md6
-rwxr-xr-xcron-jobs/db-cleanup48
-rw-r--r--db-cleanup.conf21
-rw-r--r--systemd/db-cleanup.service7
-rw-r--r--systemd/db-cleanup.timer9
5 files changed, 91 insertions, 0 deletions
diff --git a/README.md b/README.md
index 4072a6a..7522376 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,7 @@ The executables that you (might) care about are:
dbscripts/
├── cron-jobs/
+ │   ├── db-cleanup [Parabola only]
│   ├── devlist-mailer
│   ├── ftpdir-cleanup
│   ├── integrity-check
@@ -44,6 +45,11 @@ When we remove a package from a repository, it stays in the package
the pool, to reclaim the disk space:
- `cron-jobs/ftpdir-cleanup`
+ - `cron-jobs/db-cleanup`
+
+Both of these programs do the exact same thing. Parabola developers
+decided to write their own from scratch, instead of modifying
+`ftpdir-cleanup`. They should eventually be merged.
Things that haven't been mentioned yet:
diff --git a/cron-jobs/db-cleanup b/cron-jobs/db-cleanup
new file mode 100755
index 0000000..04a559a
--- /dev/null
+++ b/cron-jobs/db-cleanup
@@ -0,0 +1,48 @@
+#!/bin/bash
+# Syncs pools against themselves using database contents as filter to cleanup
+# them up
+# License: GPLv3
+
+# Principles
+# * Get repos dbs contents
+# * Make them a include list
+# * Rsync pools against themselves removing excluded files
+# * Instant cleanup!
+
+set -eu -o pipefail
+source "$(dirname "$(readlink -e "$0")")/../config"
+source "$(dirname "$(readlink -e "$0")")/../db-cleanup.conf"
+source "$(librelib messages)"
+setup_traps
+
+EXTRAFLAGS=()
+if [[ $CLEANUP_DRYRUN = true ]]; then
+ EXTRAFLAGS+=(--dry-run)
+fi
+
+filter=$(mktemp -t "${0##*/}.XXXXXXXXXX")
+trap "rm -f -- ${filter@Q}" EXIT
+
+for dbfile in "${FTP_BASE}"/*/os/*/*.db; do
+ msg 'Processing %s' "$dbfile"
+ bsdtar tf "${dbfile}"
+done | cut -d'/' -f1 | sort -u | sed "s|$|*|" > "$filter"
+
+msg "Removing old files:"
+
+for POOL in "${PKGPOOLS[@]}" "${SRCPOOLS[@]}"; do
+ msg2 '%s' "${POOL}"
+
+ rsync "${EXTRAFLAGS[@]}" -va --delete-excluded \
+ --include-from="$filter" \
+ --exclude="*" \
+ "${FTP_BASE}/${POOL}/" \
+ "${FTP_BASE}/${POOL}/"
+done
+
+msg "Removing dead symlinks:"
+actions=(-print)
+if [[ $CLEANUP_DRYRUN != true ]]; then
+ actions+=(-delete)
+fi
+find -L "${FTP_BASE}/" -type l "${actions[@]}"
diff --git a/db-cleanup.conf b/db-cleanup.conf
new file mode 100644
index 0000000..12d65f9
--- /dev/null
+++ b/db-cleanup.conf
@@ -0,0 +1,21 @@
+#!/hint/bash
+
+# Both PKGPOOLS and SRCPOOLS are relative to `config:FTP_BASE`.
+
+# Directories where packages are shared between repos
+PKGPOOLS=(
+ pool/parabola # Parabola GNU/Linux-libre
+ pool/alarm # Arch Linux ARM
+ pool/archlinux32 # Arch Linux 32-bits
+ pool/packages # Arch Linux (project)
+ pool/community # Arch Linux (community)
+)
+
+# Directories where sources are stored
+SRCPOOLS=(
+ sources/parabola # Parabola GNU/Linux-libre
+ sources/alarm # Arch Linux ARM
+ sources/archlinux32 # Arch Linux 32-bits
+ sources/packages # Arch Linux (project)
+ sources/community # Arch Linux (community)
+)
diff --git a/systemd/db-cleanup.service b/systemd/db-cleanup.service
new file mode 100644
index 0000000..669f87e
--- /dev/null
+++ b/systemd/db-cleanup.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Clean up old files
+
+[Service]
+Type=oneshot
+User=repo
+ExecStart=/opt/dbscripts/cron-jobs/db-cleanup
diff --git a/systemd/db-cleanup.timer b/systemd/db-cleanup.timer
new file mode 100644
index 0000000..8a1c5da
--- /dev/null
+++ b/systemd/db-cleanup.timer
@@ -0,0 +1,9 @@
+[Unit]
+Description=Periodic cleaning of old packages
+
+[Timer]
+OnCalendar=Sun,Tue,Thu,Sat *-*-* 14:13:00
+Persistent=true
+
+[Install]
+WantedBy=timers.target