mongodb: Add database backups
This commit is contained in:
parent
195d9c3b03
commit
e233860b7b
3 changed files with 49 additions and 0 deletions
28
roles/mongodb/templates/mongodb-backup.sh.j2
Executable file
28
roles/mongodb/templates/mongodb-backup.sh.j2
Executable 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)/"
|
Loading…
Add table
Add a link
Reference in a new issue