Compare commits
No commits in common. "d4c85a48f643805f88345387979ba3f2b33187f8" and "c585abc7a825337dc7507da1aa4a4416f5a8ba2a" have entirely different histories.
d4c85a48f6
...
c585abc7a8
3 changed files with 36 additions and 70 deletions
|
@ -1 +1 @@
|
||||||
VERSION=1.0.8 $@
|
VERSION=1.0.4 $@
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
backup_file_path='files'
|
#! /bin/bash
|
||||||
|
|
||||||
function init-file-repo() {
|
function init-file-repo() {
|
||||||
if [ -z ${CERTIFICATE_FILE} ];
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
then
|
then
|
||||||
restic -r ${RESTIC_REPOSITORY}/${backup_file_path} -v init
|
restic -r ${RESTIC_REPOSITORY}/files -v init
|
||||||
else
|
else
|
||||||
restic -r ${RESTIC_REPOSITORY}/${backup_file_path} -v init --cacert ${CERTIFICATE_FILE}
|
restic -r ${RESTIC_REPOSITORY}/files -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}/${backup_file_path} unlock --cleanup-cache
|
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache
|
||||||
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} backup .
|
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/files backup .
|
||||||
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
|
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
|
||||||
else
|
else
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
||||||
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} backup . --cacert ${CERTIFICATE_FILE}
|
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/files backup . --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}
|
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}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,39 +31,29 @@ function backup-fs-from-directory() {
|
||||||
|
|
||||||
if [ -z ${CERTIFICATE_FILE} ];
|
if [ -z ${CERTIFICATE_FILE} ];
|
||||||
then
|
then
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache
|
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache
|
||||||
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} backup $@
|
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/files backup $@
|
||||||
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
|
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
|
||||||
else
|
else
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
||||||
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} backup $@ --cacert ${CERTIFICATE_FILE}
|
cd ${directory} && restic -v -r ${RESTIC_REPOSITORY}/files backup $@ --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}
|
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}
|
||||||
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}/${backup_file_path} unlock --cleanup-cache
|
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache
|
||||||
rm -rf ${directory}*
|
rm -rf ${directory}*
|
||||||
restic -v -r $RESTIC_REPOSITORY/${backup_file_path} restore ${snapshot_id} --target ${directory}
|
restic -v -r $RESTIC_REPOSITORY/files restore latest --target ${directory}
|
||||||
else
|
else
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
restic -v -r ${RESTIC_REPOSITORY}/files unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
|
||||||
rm -rf ${directory}*
|
rm -rf ${directory}*
|
||||||
restic -v -r $RESTIC_REPOSITORY/${backup_file_path} restore ${snapshot_id} --target ${directory} --cacert ${CERTIFICATE_FILE}
|
restic -v -r $RESTIC_REPOSITORY/files restore latest --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,8 +1,5 @@
|
||||||
backup_pg_role_path='pg-role'
|
|
||||||
backup_pg_database_path='pg-database'
|
|
||||||
|
|
||||||
function init-command() {
|
function init-command() {
|
||||||
restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} -v init $@
|
restic -r ${RESTIC_REPOSITORY}/pg-role -v init $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function init-role-repo() {
|
function init-role-repo() {
|
||||||
|
@ -17,7 +14,7 @@ function init-role-repo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init-database-command() {
|
function init-database-command() {
|
||||||
restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} -v init $@
|
restic -r ${RESTIC_REPOSITORY}/pg-database -v init $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function init-database-repo() {
|
function init-database-repo() {
|
||||||
|
@ -46,11 +43,11 @@ function create-pg-pass() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function roles-unlock-command() {
|
function roles-unlock-command() {
|
||||||
restic -v -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} unlock --cleanup-cache $@
|
restic -v -r ${RESTIC_REPOSITORY}/pg-role unlock --cleanup-cache $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function roles-forget-command() {
|
function roles-forget-command() {
|
||||||
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 $@
|
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 $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function backup-roles() {
|
function backup-roles() {
|
||||||
|
@ -60,22 +57,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}/${backup_pg_role_path} backup --stdin
|
grep ${role_prefix} | restic -r ${RESTIC_REPOSITORY}/pg-role 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}/${backup_pg_role_path} backup --stdin --cacert ${CERTIFICATE_FILE}
|
grep ${role_prefix} | restic -r ${RESTIC_REPOSITORY}/pg-role 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}/${backup_pg_database_path} unlock --cleanup-cache $@
|
restic -v -r ${RESTIC_REPOSITORY}/pg-database unlock --cleanup-cache $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function db-forget-command() {
|
function db-forget-command() {
|
||||||
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 $@
|
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 $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function backup-db-dump() {
|
function backup-db-dump() {
|
||||||
|
@ -85,65 +82,44 @@ 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}/${backup_pg_database_path} backup --stdin
|
restic -r ${RESTIC_REPOSITORY}/pg-database 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}/${backup_pg_database_path} backup --stdin --cacert ${CERTIFICATE_FILE}
|
restic -r ${RESTIC_REPOSITORY}/pg-database 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}/${backup_pg_role_path} dump ${snapshot_id} stdin | \
|
restic -r ${RESTIC_REPOSITORY}/pg-role dump latest 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}/${backup_pg_role_path} dump ${snapshot_id} stdin --cacert ${CERTIFICATE_FILE} | \
|
restic -r ${RESTIC_REPOSITORY}/pg-role dump latest 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}/${backup_pg_database_path} dump ${snapshot_id} stdin | \
|
restic -r ${RESTIC_REPOSITORY}/pg_database dump latest 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}/${backup_pg_database_path} dump ${snapshot_id} stdin --cacert ${CERTIFICATE_FILE} | \
|
restic -r ${RESTIC_REPOSITORY}/pg_database dump latest 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