mongodb: Add database backups

This commit is contained in:
Timo Makinen 2024-06-22 18:51:49 +00:00
parent 195d9c3b03
commit e233860b7b
3 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,28 @@
#!/bin/sh
set -eu
umask 027
DESTDIR="/srv/backup"
DATE="$(date +%Y-%m-%d)"
cd "$DESTDIR"
find . -xdev -mindepth 2 -maxdepth 2 -type f -mtime +30 \
-execdir rm -f -- {} \;
find . -xdev -depth -mindepth 1 -maxdepth 1 -type d -empty \
-execdir rmdir -- {} \;
mkdir -m 2750 "$DATE"
chgrp backup "$DATE"
mongodump \
--sslPEMKeyFile=/etc/pki/tls/private/mongodb.pem \
--sslCAFile=/etc/pki/tls/certs/ca.crt \
--ssl \
--username=backup \
--password="{{ mongodb_backup_password }}" \
--gzip \
--out="${DATE}" \
--quiet \
--uri="mongodb://$(hostname -f)/"