aboutsummaryrefslogtreecommitdiff
path: root/src/infrastructure/scripts/gc.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/infrastructure/scripts/gc.sh')
-rwxr-xr-xsrc/infrastructure/scripts/gc.sh146
1 files changed, 0 insertions, 146 deletions
diff --git a/src/infrastructure/scripts/gc.sh b/src/infrastructure/scripts/gc.sh
deleted file mode 100755
index e037f3c..0000000
--- a/src/infrastructure/scripts/gc.sh
+++ /dev/null
@@ -1,146 +0,0 @@
-#!/bin/sh
-set -eu
-
-usage() {
- cat <<-'EOF'
- Usage:
- gc [TYPE]
- gc -h
- EOF
-}
-
-help() {
- cat <<-'EOF'
-
-
- Options:
- -h, --help show this message
-
- TYPE what to do GC on (default: all):
- - guix
- - deploy
- - trash
- - tmpdir
- - logs
-
-
- GC the server, deleting old, unusable data, in order to free
- disk space system-wide.
-
-
- Examples:
-
- Just run it, for all:
-
- $ gc
-
-
- Cleanup tmpdir:
-
- $ gc tmpdir
- EOF
-}
-
-
-for flag in "$@"; do
- case "$flag" in
- --)
- break
- ;;
- --help)
- usage
- help
- exit
- ;;
- *)
- ;;
- esac
-done
-
-while getopts 'h' flag; do
- case "$flag" in
- h)
- usage
- help
- exit
- ;;
- *)
- usage >&2
- exit 2
- ;;
- esac
-done
-shift $((OPTIND - 1))
-
-
-if [ "$(id -un)" != 'root' ]; then
- printf 'This script must be run as root.\n\n' >&2
- usage >&2
- exit 2
-fi
-
-
-disk() {
- df -h / /mnt/backup/ |
- tail -n +2 |
- awk '{ printf "%s\t%s/%s\t%s\n", $4, $3, $2, $6 }'
-}
-
-today() {
- date '+%Y-%m-%d'
-}
-
-gc_guix() {
- sudo -i guix system delete-generations 1m
- sudo -i guix gc -d 1m
-}
-
-gc_deploy() {
- find /opt/deploy \
- ! -path /opt/deploy -prune \
- -type d \
- -not -name "$(today)*" \
- -exec rm -rvf "{}" ';'
-}
-
-gc_trash() {
- yes | sudo -i trash-empty
-}
-
-gc_tmpdir() {
- find "${TMPDIR:-/tmp}" -atime +10 -exec rm -vf "{}" ';'
-}
-
-gc_logs() {
- find /var/log/ci/ -atime +10 -exec rm -vf "{}" ';'
-}
-
-
-gc_all() {
- gc_guix
- gc_deploy
- gc_trash
- gc_tmpdir
- gc_logs
-}
-
-
-TYPE="${1:-all}"
-CMD=gc_"$TYPE"
-if ! command -v "$CMD" >/dev/null; then
- printf 'Invalid TYPE: "%s".\n\n' "$TYPE" >&2
- usage >&2
- exit 2
-fi
-
-BEFORE="$(disk)"
-set -x
-"$CMD"
-set +x
-AFTER="$(disk)"
-
-cat <<-EOF
- Disk space:
- before: $BEFORE
- after: $AFTER
-EOF