wip
This commit is contained in:
parent
26a1fb2512
commit
abef612581
8 changed files with 30 additions and 136 deletions
|
@ -0,0 +1,3 @@
|
|||
function init-file-repo() {
|
||||
restic -r ${RESTIC_REPOSITORY}/files -v init
|
||||
}
|
|
@ -1,3 +1,27 @@
|
|||
function init-role-repo() {
|
||||
restic -r ${RESTIC_REPOSITORY}/pg-role -v init
|
||||
}
|
||||
|
||||
function init-database-repo() {
|
||||
restic -r ${RESTIC_REPOSITORY}/pg-database -v init
|
||||
}
|
||||
|
||||
function create-pg-pass() {
|
||||
local pg_host=${POSTGRES_HOST:-loclahost}
|
||||
|
||||
echo "${pg_host}:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD}" > /root/.pgpass
|
||||
echo "${POSTGRES_HOST}:template1:${POSTGRES_USER}:${POSTGRES_PASSWORD}" >> /root/.pgpass
|
||||
chmod 0600 /root/.pgpass
|
||||
}
|
||||
|
||||
function backup-roles() {
|
||||
local role_prefix="$1"; shift
|
||||
|
||||
restic -v -r ${RESTIC_REPOSITORY}/pg-role unlock --cleanup-cache
|
||||
|
||||
pg_dumpall -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U${POSTGRES_USER} --no-password --roles-only |
|
||||
grep "${role_prefix}" |
|
||||
restic -v -r ${RESTIC_REPOSITORY}/pg-role backup --stdin
|
||||
|
||||
restic -v -r ${RESTIC_REPOSITORY}/pg-role forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --prune
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -o pipefail
|
||||
|
||||
function main() {
|
||||
|
||||
#Start maintenance mode
|
||||
/usr/local/bin/start-maintenance.sh
|
||||
|
||||
file_env AWS_ACCESS_KEY_ID
|
||||
file_env AWS_SECRET_ACCESS_KEY
|
||||
|
||||
file_env POSTGRES_DB
|
||||
file_env POSTGRES_PASSWORD
|
||||
file_env POSTGRES_USER
|
||||
|
||||
file_env RESTIC_PASSWORD
|
||||
file_env RESTIC_DAYS_TO_KEEP 14
|
||||
|
||||
# backup roles
|
||||
restic -v -r ${RESTIC_REPOSITORY}/pg-role unlock --cleanup-cache
|
||||
|
||||
pg_dumpall -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U${POSTGRES_USER} --no-password --roles-only |
|
||||
grep 'oc_' |
|
||||
restic -v -r ${RESTIC_REPOSITORY}/pg-role backup --stdin
|
||||
|
||||
restic -v -r ${RESTIC_REPOSITORY}/pg-role forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --prune
|
||||
|
||||
# backup database dump
|
||||
restic -v -r ${RESTIC_REPOSITORY}/pg-database unlock --cleanup-cache
|
||||
|
||||
pg_dump -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} \
|
||||
-U ${POSTGRES_USER} --no-password --serializable-deferrable |
|
||||
restic -v -r ${RESTIC_REPOSITORY}/pg-database backup --stdin
|
||||
|
||||
restic -v -r ${RESTIC_REPOSITORY}/pg-database forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --prune
|
||||
|
||||
# backup nextcloud filesystem
|
||||
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache
|
||||
|
||||
cd /var/backups/ && restic -v -r ${RESTIC_REPOSITORY}/files backup .
|
||||
|
||||
restic -v -r ${RESTIC_REPOSITORY}/files forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --prune
|
||||
|
||||
#End maintenance mode
|
||||
/usr/local/bin/end-maintenance.sh
|
||||
}
|
||||
|
||||
source /usr/local/lib/functions.sh
|
||||
main
|
|
@ -1,19 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
function main() {
|
||||
file_env POSTGRES_DB
|
||||
file_env POSTGRES_PASSWORD
|
||||
file_env POSTGRES_USER
|
||||
|
||||
echo "${POSTGRES_HOST}:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD}" > /root/.pgpass
|
||||
echo "${POSTGRES_HOST}:template1:${POSTGRES_USER}:${POSTGRES_PASSWORD}" >> /root/.pgpass
|
||||
chmod 0600 /root/.pgpass
|
||||
|
||||
# Idle process
|
||||
while true; do
|
||||
sleep 500000
|
||||
done
|
||||
}
|
||||
|
||||
source /usr/local/lib/functions.sh
|
||||
main
|
|
@ -1,15 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
function main() {
|
||||
file_env AWS_ACCESS_KEY_ID
|
||||
file_env AWS_SECRET_ACCESS_KEY
|
||||
|
||||
file_env RESTIC_PASSWORD_FILE
|
||||
|
||||
restic -r ${RESTIC_REPOSITORY}/pg-role -v init
|
||||
restic -r ${RESTIC_REPOSITORY}/pg-database -v init
|
||||
restic -r ${RESTIC_REPOSITORY}/files -v init
|
||||
}
|
||||
|
||||
source /usr/local/lib/functions.sh
|
||||
main
|
|
@ -12,3 +12,4 @@ update-ca-certificates
|
|||
|
||||
install -m 0400 /tmp/functions.sh /usr/local/lib/
|
||||
install -m 0400 /tmp/backup-pg-functions.sh /usr/local/lib/
|
||||
install -m 0400 /tmp/backup-file-functions.sh /usr/local/lib/
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -Eeo pipefail
|
||||
|
||||
function main() {
|
||||
|
||||
#Start maintenance mode
|
||||
#/usr/local/bin/start-maintenance.sh
|
||||
|
||||
file_env AWS_ACCESS_KEY_ID
|
||||
file_env AWS_SECRET_ACCESS_KEY
|
||||
|
||||
file_env POSTGRES_DB
|
||||
file_env POSTGRES_PASSWORD
|
||||
file_env POSTGRES_USER
|
||||
|
||||
file_env RESTIC_PASSWORD
|
||||
|
||||
# create new db
|
||||
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
||||
--no-password -c "DROP DATABASE \"${POSTGRES_DB}\";"
|
||||
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
||||
--no-password -c "CREATE DATABASE \"${POSTGRES_DB}\";"
|
||||
|
||||
# init restic
|
||||
restic -v -r ${RESTIC_REPOSITORY}/pg-role snapshots
|
||||
|
||||
# restore roles
|
||||
restic -r ${RESTIC_REPOSITORY}/pg-role dump latest stdin | \
|
||||
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
||||
--no-password
|
||||
|
||||
# restore db
|
||||
restic -r ${RESTIC_REPOSITORY}/pg-database dump latest stdin | \
|
||||
psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
||||
--no-password
|
||||
|
||||
# files
|
||||
rm -rf /var/backups/*
|
||||
restic -v -r $RESTIC_REPOSITORY/files restore latest --target /var/backups/
|
||||
|
||||
# adjust trusted domains
|
||||
php /var/www/html/occ config:system:set trusted_domains 1 --value=cloud.test.meissa-gmbh.de
|
||||
|
||||
#End maintenance mode
|
||||
#/usr/local/bin/end-maintenance.sh
|
||||
}
|
||||
|
||||
source /usr/local/lib/functions.sh
|
||||
main
|
||||
|
|
@ -2,4 +2,5 @@
|
|||
{:name "postgresql-client-13"}]
|
||||
:file [{:path "/entrypoint.sh" :mod "700"}
|
||||
{:path "/usr/local/lib/functions.sh" :mod "400"}
|
||||
{:path "/usr/local/lib/backup-pg-functions.sh" :mod "400"}]}
|
||||
{:path "/usr/local/lib/backup-pg-functions.sh" :mod "400"}
|
||||
{:path "/usr/local/lib/backup-file-functions.sh" :mod "400"}]}
|
||||
|
|
Loading…
Reference in a new issue