Last active
March 4, 2021 15:39
-
-
Save mattrude/b0ac735d07b0031bb002 to your computer and use it in GitHub Desktop.
A simple script to export the full database of a sks server to a chosen location.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script will stop the sks server, dump it's contents to | |
# the $PREDIR, then restart the sks server. | |
# | |
# Matt Rude <[email protected]> PGP: 0xDD23BF73 | |
# URL: https://gist.github.com/mattrude/b0ac735d07b0031bb002 | |
SKSDATE=`date +%Y-%m-%d` | |
USER="debian-sks" | |
INDIR="/var/lib/sks" | |
PREDIR="/external/sks-dump" | |
OUTDIR="$PREDIR/$SKSDATE" | |
for DEL in `ls -1t $PREDIR |grep -v 'current' |tail -n +7` | |
do | |
echo "Deleting old directory $PREDIR/$DEL" | |
rm -rf $PREDIR/$DEL | |
done | |
/usr/sbin/service sks stop | |
if [ `ps -eaf |grep "sks " |grep -v 'grep sks' |wc -l` == "0" ]; then | |
mkdir -p $INDIR | |
chown -R $USER:$USER $INDIR | |
cd $INDIR | |
rm -rf $OUTDIR && mkdir -p $OUTDIR && \ | |
chown -R $USER:$USER $PREDIR && \ | |
sudo -u $USER /usr/local/bin/sks dump 15000 $OUTDIR/ sks-dump | |
if [ `ps -eaf |grep "sks " |grep -v 'grep sks' |wc -l` == 0 ]; then | |
chown -R $USER:$USER $INDIR | |
/usr/sbin/service sks start | |
else | |
echo "Unable to start SKS since it was already running." | |
exit 1 | |
fi | |
cd $PREDIR/ | |
if [ ! -d current ]; then | |
mkdir current | |
fi | |
umount current | |
mount --bind $OUTDIR current | |
else | |
echo "Unable run backup, SKS is still running." | |
exit 1 | |
fi | |
SIZE=`du -shc $OUTDIR |grep 'total' |awk '{ print $1 }'` | |
echo "This is the PGP key server dump from keyserver.mattrude.com created: `date -u` | |
On a linux/unix system, you may download this directory via the following command: | |
wget -c -r -p -e robots=off --timestamping --level=1 --cut-dirs=3 --no-host-directories http://keyserver.mattrude.com/dump/current/ | |
These files were created with the following command: sks dump 15000 $SKSDATE/ sks-dump | |
The current archive size is approximately: $SIZE | |
For more information on importing keys from dump files, please see http://www.keysigning.org/sks/" > $OUTDIR/README.txt | |
chown -R $USER:$USER $PREDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the script! I sucessfully used it as a template for my own sks.