Files
labca/backup
Arjan H 0ed9d8eac2 Build and use local docker images for docker-only setup (#41)
For now, the images are still built on the target machine for testing,
in the end they need to be built in a GitHub action.
2023-04-15 09:19:17 +02:00

35 lines
723 B
Bash
Executable File

#!/usr/bin/env bash
set -e
NOW=$(date +%y%m%d-%H%M%S)
CRON=""
if [ "$1" == "cron" ]; then
CRON="_${1}"
TODAY=`date '+%Y_%m_%d'`
echo "Running cron-$(basename $0) for ${TODAY}..."
fi
BASE=${NOW}_${HOSTNAME}${CRON}
TMPDIR=/tmp/$BASE
mkdir -p $TMPDIR
mkdir -p /opt/backup
cd /opt/boulder
docker-compose exec -T bmysql mysqldump boulder_sa_integration >$TMPDIR/boulder_sa_integration.sql
cp -p /etc/nginx/ssl/*key* /etc/nginx/ssl/*cert.pem /etc/nginx/ssl/*.csr $TMPDIR/
cp -rp /opt/labca/data $TMPDIR/
cd /tmp
tar czf /opt/backup/$BASE.tgz $BASE
rm -rf $TMPDIR
# housekeeping
find /opt/backup -name "*_cron_*.tgz" -mtime +31 -exec rm -rf {} \;
if [ "$1" != "cron" ]; then
echo /opt/backup/$BASE.tgz
fi