Compare commits
10 commits
c585abc7a8
...
d4c85a48f6
Author | SHA1 | Date | |
---|---|---|---|
d4c85a48f6 | |||
|
067444c7d6 | ||
|
f60f8c8adf | ||
5f5e061e36 | |||
d3b4c41d22 | |||
9654c4fbe2 | |||
f45d943d3f | |||
c6c523edee | |||
7652273297 | |||
1986d0115f |
3 changed files with 70 additions and 36 deletions
|
@ -1 +1 @@
|
||||||
VERSION=1.0.4 $@
|
VERSION=1.0.8 $@
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#! /bin/bash
|
backup_file_path='files'
|
||||||
|
|
||||||
function init-file-repo() {
|
function init-file-repo() {
|
||||||
if [ -z ${CERTIFICATE_FILE} ];
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
then
|
then
|
||||||
restic -r ${RESTIC_REPOSITORY}/files -v init
|
restic -r ${RESTIC_REPOSITORY}/${backup_file_path} -v init
|
||||||
else
|
else
|
||||||
restic -r ${RESTIC_REPOSITORY}/files -v init --cacert ${CERTIFICATE_FILE}
|
restic -r ${RESTIC_REPOSITORY}/${backup_file_path} -v init --cacert ${CERTIFICATE_FILE}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,13 +15,13 @@ function backup-directory() {
|
||||||
|
|
||||||
if [ -z ${CERTIFICATE_FILE} ];
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
then
|
then
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache
|
||||||
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/files backup .
|
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} backup .
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/files forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --keep-within-monthly ${RESTIC_MONTHS_TO_KEEP}m --prune
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} forget --group-by '' --keep-last 1 --keep-daily ${RESTIC_DAYS_TO_KEEP} --keep-monthly ${RESTIC_MONTHS_TO_KEEP} --prune
|
||||||
else
|
else
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
||||||
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/files backup . --cacert ${CERTIFICATE_FILE}
|
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} backup . --cacert ${CERTIFICATE_FILE}
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/files forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --keep-within-monthly ${RESTIC_MONTHS_TO_KEEP}m --prune --cacert ${CERTIFICATE_FILE}
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} forget --group-by '' --keep-last 1 --keep-daily ${RESTIC_DAYS_TO_KEEP} --keep-monthly ${RESTIC_MONTHS_TO_KEEP} --prune --cacert ${CERTIFICATE_FILE}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,29 +31,39 @@ function backup-fs-from-directory() {
|
||||||
|
|
||||||
if [ -z ${CERTIFICATE_FILE} ];
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
then
|
then
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache
|
||||||
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/files backup $@
|
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} backup $@
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/files forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --keep-within-monthly ${RESTIC_MONTHS_TO_KEEP}m --prune
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} forget --group-by '' --keep-last 1 --keep-daily ${RESTIC_DAYS_TO_KEEP} --keep-monthly ${RESTIC_MONTHS_TO_KEEP} --prune
|
||||||
else
|
else
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
||||||
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/files backup $@ --cacert ${CERTIFICATE_FILE}
|
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} backup $@ --cacert ${CERTIFICATE_FILE}
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/files forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --keep-within-monthly ${RESTIC_MONTHS_TO_KEEP}m --prune --cacert ${CERTIFICATE_FILE}
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} forget --group-by '' --keep-last 1 --keep-daily ${RESTIC_DAYS_TO_KEEP} --keep-monthly ${RESTIC_MONTHS_TO_KEEP} --prune --cacert ${CERTIFICATE_FILE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore-directory() {
|
function restore-directory() {
|
||||||
local directory="$1"; shift
|
local directory="$1"; shift
|
||||||
|
local snapshot_id="${1:-latest}"; shift
|
||||||
|
|
||||||
if [ -z ${CERTIFICATE_FILE} ];
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
then
|
then
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache
|
||||||
rm -rf ${directory}*
|
rm -rf ${directory}*
|
||||||
restic -v -r $RESTIC_REPOSITORY/files restore latest --target ${directory}
|
restic -v -r $RESTIC_REPOSITORY/${backup_file_path} restore ${snapshot_id} --target ${directory}
|
||||||
else
|
else
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
||||||
rm -rf ${directory}*
|
rm -rf ${directory}*
|
||||||
restic -v -r $RESTIC_REPOSITORY/files restore latest --target ${directory} --cacert ${CERTIFICATE_FILE}
|
restic -v -r $RESTIC_REPOSITORY/${backup_file_path} restore ${snapshot_id} --target ${directory} --cacert ${CERTIFICATE_FILE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function list-snapshot-files() {
|
||||||
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
|
then
|
||||||
|
restic -r ${RESTIC_REPOSITORY}/${backup_file_path} snapshots
|
||||||
|
else
|
||||||
|
restic -r ${RESTIC_REPOSITORY}/${backup_file_path} snapshots --cacert ${CERTIFICATE_FILE}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
backup_pg_role_path='pg-role'
|
||||||
|
backup_pg_database_path='pg-database'
|
||||||
|
|
||||||
function init-command() {
|
function init-command() {
|
||||||
restic -r ${RESTIC_REPOSITORY}/pg-role -v init $@
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} -v init $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function init-role-repo() {
|
function init-role-repo() {
|
||||||
|
@ -14,7 +17,7 @@ function init-role-repo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init-database-command() {
|
function init-database-command() {
|
||||||
restic -r ${RESTIC_REPOSITORY}/pg-database -v init $@
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} -v init $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function init-database-repo() {
|
function init-database-repo() {
|
||||||
|
@ -43,11 +46,11 @@ function create-pg-pass() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function roles-unlock-command() {
|
function roles-unlock-command() {
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/pg-role unlock --cleanup-cache $@
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} unlock --cleanup-cache $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function roles-forget-command() {
|
function roles-forget-command() {
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/pg-role forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --keep-within-monthly ${RESTIC_MONTHS_TO_KEEP}m --prune $@
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} forget --group-by '' --keep-last 1 --keep-daily ${RESTIC_DAYS_TO_KEEP} --keep-monthly ${RESTIC_MONTHS_TO_KEEP} --prune $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function backup-roles() {
|
function backup-roles() {
|
||||||
|
@ -57,22 +60,22 @@ function backup-roles() {
|
||||||
then
|
then
|
||||||
roles-unlock-command
|
roles-unlock-command
|
||||||
pg_dumpall -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U${POSTGRES_USER} --no-password --roles-only | \
|
pg_dumpall -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U${POSTGRES_USER} --no-password --roles-only | \
|
||||||
grep ${role_prefix} | restic -r ${RESTIC_REPOSITORY}/pg-role backup --stdin
|
grep ${role_prefix} | restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} backup --stdin
|
||||||
roles-forget-command
|
roles-forget-command
|
||||||
else
|
else
|
||||||
roles-unlock-command --cacert ${CERTIFICATE_FILE}
|
roles-unlock-command --cacert ${CERTIFICATE_FILE}
|
||||||
pg_dumpall -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U${POSTGRES_USER} --no-password --roles-only | \
|
pg_dumpall -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U${POSTGRES_USER} --no-password --roles-only | \
|
||||||
grep ${role_prefix} | restic -r ${RESTIC_REPOSITORY}/pg-role backup --stdin --cacert ${CERTIFICATE_FILE}
|
grep ${role_prefix} | restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} backup --stdin --cacert ${CERTIFICATE_FILE}
|
||||||
roles-forget-command --cacert ${CERTIFICATE_FILE}
|
roles-forget-command --cacert ${CERTIFICATE_FILE}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function db-unlock-command() {
|
function db-unlock-command() {
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/pg-database unlock --cleanup-cache $@
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} unlock --cleanup-cache $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function db-forget-command() {
|
function db-forget-command() {
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/pg-database forget --keep-last 1 --keep-within ${RESTIC_DAYS_TO_KEEP}d --keep-within-monthly ${RESTIC_MONTHS_TO_KEEP}m --prune $@
|
restic -v -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} forget --group-by '' --keep-last 1 --keep-daily ${RESTIC_DAYS_TO_KEEP} --keep-monthly ${RESTIC_MONTHS_TO_KEEP} --prune $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function backup-db-dump() {
|
function backup-db-dump() {
|
||||||
|
@ -82,44 +85,65 @@ function backup-db-dump() {
|
||||||
db-unlock-command
|
db-unlock-command
|
||||||
pg_dump -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} \
|
pg_dump -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} \
|
||||||
-U ${POSTGRES_USER} --no-password --serializable-deferrable | \
|
-U ${POSTGRES_USER} --no-password --serializable-deferrable | \
|
||||||
restic -r ${RESTIC_REPOSITORY}/pg-database backup --stdin
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} backup --stdin
|
||||||
db-forget-command
|
db-forget-command
|
||||||
else
|
else
|
||||||
db-unlock-command --cacert ${CERTIFICATE_FILE}
|
db-unlock-command --cacert ${CERTIFICATE_FILE}
|
||||||
pg_dump -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} \
|
pg_dump -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} \
|
||||||
-U ${POSTGRES_USER} --no-password --serializable-deferrable | \
|
-U ${POSTGRES_USER} --no-password --serializable-deferrable | \
|
||||||
restic -r ${RESTIC_REPOSITORY}/pg-database backup --stdin --cacert ${CERTIFICATE_FILE}
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} backup --stdin --cacert ${CERTIFICATE_FILE}
|
||||||
db-forget-command --cacert ${CERTIFICATE_FILE}
|
db-forget-command --cacert ${CERTIFICATE_FILE}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore-roles() {
|
function restore-roles() {
|
||||||
|
local snapshot_id="${1:-latest}"; shift
|
||||||
|
|
||||||
if [ -z ${CERTIFICATE_FILE} ];
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
then
|
then
|
||||||
roles-unlock-command
|
roles-unlock-command
|
||||||
restic -r ${RESTIC_REPOSITORY}/pg-role dump latest stdin | \
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} dump ${snapshot_id} stdin | \
|
||||||
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
||||||
--no-password
|
--no-password
|
||||||
else
|
else
|
||||||
roles-unlock-command --cacert ${CERTIFICATE_FILE}
|
roles-unlock-command --cacert ${CERTIFICATE_FILE}
|
||||||
restic -r ${RESTIC_REPOSITORY}/pg-role dump latest stdin --cacert ${CERTIFICATE_FILE} | \
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} dump ${snapshot_id} stdin --cacert ${CERTIFICATE_FILE} | \
|
||||||
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
||||||
--no-password
|
--no-password
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore-db() {
|
function restore-db() {
|
||||||
|
local snapshot_id="${1:-latest}"; shift
|
||||||
|
|
||||||
if [ -z ${CERTIFICATE_FILE} ];
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
then
|
then
|
||||||
db-unlock-command
|
db-unlock-command
|
||||||
restic -r ${RESTIC_REPOSITORY}/pg_database dump latest stdin | \
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} dump ${snapshot_id} stdin | \
|
||||||
psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
||||||
--no-password
|
--no-password
|
||||||
else
|
else
|
||||||
db-unlock-command --cacert ${CERTIFICATE_FILE}
|
db-unlock-command --cacert ${CERTIFICATE_FILE}
|
||||||
restic -r ${RESTIC_REPOSITORY}/pg_database dump latest stdin --cacert ${CERTIFICATE_FILE} | \
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} dump ${snapshot_id} stdin --cacert ${CERTIFICATE_FILE} | \
|
||||||
psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
|
||||||
--no-password
|
--no-password
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function list-snapshot-roles() {
|
||||||
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
|
then
|
||||||
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} snapshots
|
||||||
|
else
|
||||||
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} snapshots --cacert ${CERTIFICATE_FILE}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function list-snapshot-db() {
|
||||||
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
|
then
|
||||||
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} snapshots
|
||||||
|
else
|
||||||
|
restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} snapshots --cacert ${CERTIFICATE_FILE}
|
||||||
|
fi
|
||||||
|
}
|
Loading…
Reference in a new issue