manned/util/export.sh
2025-10-23 08:35:31 +02:00

34 lines
994 B
Bash
Executable file

#!/bin/sh
set -e
mkdir -p ../dl
# Only run once a week
[ -e ../dl/current ] && [ -z $(find ../dl/current -daystart -mtime +6) ] && exit
# Only keep the last dump
rm -rf $(printf '%s\n' ../dl/????-??-?? | sort | head -n -1)
# Create a new dump
OUT=../dl/.work
export OUT
rm -fr $OUT
mkdir -p $OUT
cp ../import.sql $OUT/import.sql
psql -wqU manned <<EOF
\copy systems to program 'zstd - -qo $OUT/systems.tsv.zst'
\copy contents (id, hash, content) to program 'zstd - -qo $OUT/contents.tsv.zst'
\copy mans to program 'zstd - -qo $OUT/mans.tsv.zst'
\copy locales to program 'zstd - -qo $OUT/locales.tsv.zst'
\copy encodings to program 'zstd - -qo $OUT/encodings.tsv.zst'
\copy packages to program 'zstd - -qo $OUT/packages.tsv.zst'
\copy package_versions to program 'zstd - -qo $OUT/package_versions.tsv.zst'
\copy files to program 'zstd - -qo $OUT/files.tsv.zst'
EOF
DATE=$(date +%F)
mv -T $OUT ../dl/$DATE
echo $DATE >../dl/current