retention added

This commit is contained in:
jem 2020-12-12 19:02:41 +01:00
parent 8288ae0fbd
commit 1be64b6fd6
2 changed files with 10 additions and 4 deletions

View file

@ -10,15 +10,20 @@ function main() {
file_env POSTGRES_PASSWORD
file_env POSTGRES_USER
file_env RESTIC_PASSWORD_FILE
file_env RESTIC_PASSWORD
file_env RESTIC_DAYS_TO_KEEP 14
# backup database dump
pg_dump -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} \
-U ${POSTGRES_USER_FILE} --no-password --serializable-deferrable | \
restic -r ${RESTIC_REPOSITORY}/db backup --stdin
restic -r ${RESTIC_REPOSITORY}/db forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --prune
# backup nextcloud filesystem
cd /var/backups/ && restic -r ${RESTIC_REPOSITORY}/files backup .
restic -r ${RESTIC_REPOSITORY}/files forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --prune
}
source /usr/local/lib/functions.sh

View file

@ -1,5 +1,6 @@
#!/bin/bash
set -o pipefail
function main() {
file_env AWS_ACCESS_KEY_ID
@ -9,11 +10,11 @@ function main() {
file_env POSTGRES_PASSWORD
file_env POSTGRES_USER
file_env RESTIC_PASSWORD_FILE
file_env RESTIC_PASSWORD
# files
rm -rf /var/backups/*
restic -r $RESTIC_REPOSITORY/files restore latest --target /var/backup/
restic -r $RESTIC_REPOSITORY/files restore latest --target /var/backups/
# db
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \