Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86b0fa122a | ||
|
|
32c320be27 | ||
|
|
500ab01790 | ||
|
|
ab58ab3ad0 | ||
|
|
7767eb58df | ||
|
|
38f467de96 | ||
|
|
8f91690f6a | ||
|
|
e860573e0c | ||
|
|
f990e86949 | ||
|
|
c929987900 | ||
|
|
6cb941818c | ||
|
|
edaf41f1af | ||
|
|
c7f2197614 | ||
|
|
88ea600e1d | ||
|
|
f396032728 | ||
|
|
18cbcea2b0 | ||
|
|
a0537a24d3 | ||
|
|
89897eb676 | ||
|
|
e1787fcfb3 |
@@ -8,13 +8,20 @@
|
|||||||
# pgsql
|
# pgsql
|
||||||
# zabbix-settings-
|
# zabbix-settings-
|
||||||
|
|
||||||
export BORG_BASE_DIR="borg/";
|
# debug and dry run
|
||||||
|
DEBUG=0;
|
||||||
DRYRUN=0;
|
DRYRUN=0;
|
||||||
|
PGSQL_SUDO=1;
|
||||||
|
# options
|
||||||
|
OPT_REMOTE="";
|
||||||
|
PGSQL_SUDO_USER="postgres";
|
||||||
|
# basic settings needed
|
||||||
TARGET_USER="";
|
TARGET_USER="";
|
||||||
TARGET_HOST="";
|
TARGET_HOST="";
|
||||||
TARGET_PORT="";
|
TARGET_PORT="";
|
||||||
TARGET_BORG_PATH="";
|
TARGET_BORG_PATH="";
|
||||||
TARGET_FOLDER="";
|
TARGET_FOLDER="";
|
||||||
|
# base folder
|
||||||
BASE_FOLDER="/usr/local/scripts/borg/";
|
BASE_FOLDER="/usr/local/scripts/borg/";
|
||||||
# those are the valid modules
|
# those are the valid modules
|
||||||
MODULE_LIST="file gitea mysql pgsql zabbix"
|
MODULE_LIST="file gitea mysql pgsql zabbix"
|
||||||
@@ -22,10 +29,13 @@ MODULE_LIST="file gitea mysql pgsql zabbix"
|
|||||||
# basic options
|
# basic options
|
||||||
# -c for config file override
|
# -c for config file override
|
||||||
# -n for dry run test
|
# -n for dry run test
|
||||||
while getopts ":c:nd" opt; do
|
while getopts ":c:snd" opt; do
|
||||||
case "${opt}" in
|
case "${opt}" in
|
||||||
c|config)
|
c|config)
|
||||||
BASE_FOLDER=${OPTARG}"/";
|
BASE_FOLDER=${OPTARG};
|
||||||
|
;;
|
||||||
|
s|nosudo)
|
||||||
|
PGSQL_SUDO=0;
|
||||||
;;
|
;;
|
||||||
d|debug)
|
d|debug)
|
||||||
DEBUG=1;
|
DEBUG=1;
|
||||||
@@ -55,6 +65,14 @@ if [ ! -f "${BASE_FOLDER}${SETTINGS_FILE}" ]; then
|
|||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
. "${BASE_FOLDER}${SETTINGS_FILE}";
|
. "${BASE_FOLDER}${SETTINGS_FILE}";
|
||||||
|
|
||||||
|
if [ ! -z "${TARGET_BORG_PATH}" ]; then
|
||||||
|
OPT_REMOTE="--remote-path="$(printf "%q" "${TARGET_BORG_PATH}");
|
||||||
|
fi;
|
||||||
|
export BORG_BASE_DIR="${BASE_FOLDER}";
|
||||||
|
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK="yes";
|
||||||
|
export BORG_RELOCATED_REPO_ACCESS_IS_OK="yes";
|
||||||
|
|
||||||
ORIG_BACKUPFILE=${BACKUP_FILE};
|
ORIG_BACKUPFILE=${BACKUP_FILE};
|
||||||
for MODULE in ${MODULE_LIST}; do
|
for MODULE in ${MODULE_LIST}; do
|
||||||
echo "************* MODULE: ${MODULE}";
|
echo "************* MODULE: ${MODULE}";
|
||||||
@@ -78,23 +96,43 @@ for MODULE in ${MODULE_LIST}; do
|
|||||||
fi;
|
fi;
|
||||||
# we dont allow special characters, so we don't need to special escape it
|
# we dont allow special characters, so we don't need to special escape it
|
||||||
REPOSITORY="${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE}";
|
REPOSITORY="${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE}";
|
||||||
|
# set sudo prefix for postgres so the cache folder stays the same
|
||||||
|
# if run as root then the foloders below have to have the user set to postgres again
|
||||||
|
# .config/borg/security/<postgresql repo id>
|
||||||
|
# .cache/borg/<postgresql repo id>
|
||||||
|
CMD_PREFIX="";
|
||||||
|
# only sudo to pgsql if sudo is set to true
|
||||||
|
if [ "${MODULE}" = "pgsql" ] && [ "${PGSQL_SUDO}" = "1" ]; then
|
||||||
|
CMD_PREFIX="sudo -E -u ${PGSQL_SUDO_USER} ";
|
||||||
|
fi;
|
||||||
echo "==== REPOSITORY: ${REPOSITORY}";
|
echo "==== REPOSITORY: ${REPOSITORY}";
|
||||||
borg list --format '{archive}{NL}' ${REPOSITORY}|grep -v "${MODULE},"|
|
borg list ${OPT_REMOTE} --format '{archive}{NL}' ${REPOSITORY}|grep -v "${MODULE},"|
|
||||||
while read i; do
|
while read i; do
|
||||||
# for gitea, zabbix we do not ADD we RENAME
|
# for gitea, zabbix we do not ADD we RENAME
|
||||||
if [ "${MODILE}" = "gitea" ]; then
|
if [ "${MODULE}" = "gitea" ]; then
|
||||||
target_name=$(echo $i | sed -e 's/gitea-/gitea,/');
|
# if just date, add gitea,
|
||||||
elif [ "${MODILE}" = "zabbix" ]; then
|
# else rename
|
||||||
target_name=$(echo $i | sed -e 's/zabbix-settings-/zabbix,settings-/');
|
if [ ! -z "${i##gitea*}" ]; then
|
||||||
|
target_name="${MODULE},${i}";
|
||||||
|
else
|
||||||
|
target_name=$(echo $i | sed -e 's/gitea-/gitea,/');
|
||||||
|
fi;
|
||||||
|
elif [ "${MODULE}" = "zabbix" ]; then
|
||||||
|
# if zabbix is missing, prefix
|
||||||
|
if [ ! -z "${i##zabbix*}" ]; then
|
||||||
|
target_name="${MODULE},${i}";
|
||||||
|
else
|
||||||
|
target_name=$(echo $i | sed -e 's/zabbix-settings-/zabbix,settings-/');
|
||||||
|
fi;
|
||||||
else
|
else
|
||||||
target_name="${MODULE},${i}";
|
target_name="${MODULE},${i}";
|
||||||
fi;
|
fi;
|
||||||
echo "- Rename from: ${i} to: ${target_name}";
|
echo "- Rename from: ${i} to: ${target_name}";
|
||||||
if [ ${DEBUG} -eq 1 ]; then
|
if [ ${DEBUG} -eq 1 ]; then
|
||||||
echo "borg rename -p -v ${REPOSITORY}::${i} ${target_name}";
|
echo "${CMD_PREFIX}borg rename ${OPT_REMOTE} -p -v ${REPOSITORY}::${i} ${target_name}";
|
||||||
fi;
|
fi;
|
||||||
if [ ${DRYRUN} -eq 0 ]; then
|
if [ ${DRYRUN} -eq 0 ]; then
|
||||||
borg rename -p -v ${REPOSITORY}::${i} ${target_name};
|
${CMD_PREFIX}borg rename ${OPT_REMOTE} -p -v ${REPOSITORY}::${i} ${target_name};
|
||||||
fi;
|
fi;
|
||||||
done;
|
done;
|
||||||
done;
|
done;
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ if [ ! -w "${HOME}" ] || [ "${HOME}" = '/' ]; then
|
|||||||
fi;
|
fi;
|
||||||
|
|
||||||
# keep optionfs (for files)
|
# keep optionfs (for files)
|
||||||
KEEP_OPTIONS=();
|
KEEP_OPTIONS=("");
|
||||||
# keep info string (for files)
|
# keep info string (for files)
|
||||||
KEEP_INFO="";
|
KEEP_INFO="";
|
||||||
# override standard keep for tagged backups
|
# override standard keep for tagged backups
|
||||||
@@ -304,14 +304,14 @@ fi;
|
|||||||
# PRINT OUT current data, only do this if REPO exists
|
# PRINT OUT current data, only do this if REPO exists
|
||||||
if [ ${PRINT} -eq 1 ]; then
|
if [ ${PRINT} -eq 1 ]; then
|
||||||
echo "--- [PRINT : $(date +'%F %T')] --[${MODULE}]------------------------------------>";
|
echo "--- [PRINT : $(date +'%F %T')] --[${MODULE}]------------------------------------>";
|
||||||
FORMAT="{archive} {comment:6} {start} - {end} [{id}] ({username}@{hostname}){NL}"
|
FORMAT="{archive:<45} {comment:6} {start} - {end} [{id}] ({username}@{hostname}){NL}"
|
||||||
# show command on debug or dry run
|
# show command on debug or dry run
|
||||||
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then
|
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then
|
||||||
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${BORG_COMMAND} list ${OPT_REMOTE} --format ${FORMAT} ${REPOSITORY}";
|
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${BORG_COMMAND} list ${OPT_REMOTE} --format ${FORMAT} ${REPOSITORY}";
|
||||||
fi;
|
fi;
|
||||||
# run info command if not a dry drun
|
# run info command if not a dry drun
|
||||||
if [ ${DRYRUN} -eq 0 ]; then
|
if [ ${DRYRUN} -eq 0 ]; then
|
||||||
borg list ${OPT_REMOTE} --format "${FORMAT}" ${REPOSITORY} ;
|
${BORG_COMMAND} list ${OPT_REMOTE} --format "${FORMAT}" ${REPOSITORY} ;
|
||||||
fi;
|
fi;
|
||||||
if [ ${VERBOSE} -eq 1 ]; then
|
if [ ${VERBOSE} -eq 1 ]; then
|
||||||
echo "";
|
echo "";
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
# unset borg settings
|
# unset borg settings
|
||||||
unset BORG_BASE_DIR BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK BORG_RELOCATED_REPO_ACCESS_IS_OK
|
unset BORG_BASE_DIR BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK BORG_RELOCATED_REPO_ACCESS_IS_OK
|
||||||
# error abort without duration and error notice
|
# error abort without duration and error notice
|
||||||
if [ $1 == 1 ]; then
|
if [ $# -ge 1 ] && [ $1 -eq 1 ]; then
|
||||||
echo "=== [ERROR: $(date +'%F %T')] ==[${MODULE}]====================================>";
|
echo "=== [ERROR: $(date +'%F %T')] ==[${MODULE}]====================================>";
|
||||||
else
|
else
|
||||||
DURATION=$[ $(date +'%s')-$START ];
|
DURATION=$[ $(date +'%s')-$START ];
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function version {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# version for all general files
|
# version for all general files
|
||||||
VERSION="4.1.1";
|
VERSION="4.2.3";
|
||||||
|
|
||||||
# borg version and borg comamnd
|
# borg version and borg comamnd
|
||||||
BORG_VERSION="";
|
BORG_VERSION="";
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
# set last edit date + time
|
# set last edit date + time
|
||||||
MODULE="pgsql"
|
MODULE="pgsql"
|
||||||
MODULE_VERSION="1.1.1";
|
MODULE_VERSION="1.2.0";
|
||||||
|
|
||||||
|
|
||||||
DIR="${BASH_SOURCE%/*}"
|
DIR="${BASH_SOURCE%/*}"
|
||||||
@@ -22,6 +22,7 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
|||||||
INCLUDE_FILE="borg.backup.pgsql.include";
|
INCLUDE_FILE="borg.backup.pgsql.include";
|
||||||
EXCLUDE_FILE="borg.backup.pgsql.exclude";
|
EXCLUDE_FILE="borg.backup.pgsql.exclude";
|
||||||
SCHEMA_ONLY_FILE="borg.backup.pgsql.schema-only";
|
SCHEMA_ONLY_FILE="borg.backup.pgsql.schema-only";
|
||||||
|
DATA_ONLY_FILE="borg.backup.pgsql.data-only";
|
||||||
# init check file
|
# init check file
|
||||||
BACKUP_INIT_CHECK="borg.backup.pgsql.init";
|
BACKUP_INIT_CHECK="borg.backup.pgsql.init";
|
||||||
|
|
||||||
@@ -195,9 +196,13 @@ else
|
|||||||
fi;
|
fi;
|
||||||
if [ ${include} -eq 1 ] && [ ${exclude} -eq 0 ]; then
|
if [ ${include} -eq 1 ] && [ ${exclude} -eq 0 ]; then
|
||||||
# set dump type
|
# set dump type
|
||||||
SCHEMA_ONLY=''; # empty for all
|
SCHEMA_ONLY='';
|
||||||
schema_flag='data'; # or data
|
schema_flag=''; # schema or data
|
||||||
|
# schema exclude over data exclude, can't have both
|
||||||
if [ -s "${BASE_FOLDER}${SCHEMA_ONLY_FILE}" ]; then
|
if [ -s "${BASE_FOLDER}${SCHEMA_ONLY_FILE}" ]; then
|
||||||
|
# default is data dump
|
||||||
|
SCHEMA_ONLY='';
|
||||||
|
schema_flag='data';
|
||||||
while read schema_db; do
|
while read schema_db; do
|
||||||
if [ "${db}" = "${schema_db}" ]; then
|
if [ "${db}" = "${schema_db}" ]; then
|
||||||
SCHEMA_ONLY='-s';
|
SCHEMA_ONLY='-s';
|
||||||
@@ -206,6 +211,23 @@ else
|
|||||||
break;
|
break;
|
||||||
fi;
|
fi;
|
||||||
done<"${BASE_FOLDER}${SCHEMA_ONLY_FILE}";
|
done<"${BASE_FOLDER}${SCHEMA_ONLY_FILE}";
|
||||||
|
elif [ -s "${BASE_FOLDER}${DATA_ONLY_FILE}" ]; then
|
||||||
|
# default to schema, unless in data list
|
||||||
|
SCHEMA_ONLY='-s';
|
||||||
|
schema_flag='schema';
|
||||||
|
while read data_db; do
|
||||||
|
if [ "${db}" = "${data_db}" ]; then
|
||||||
|
SCHEMA_ONLY='';
|
||||||
|
schema_flag='data';
|
||||||
|
# skip out
|
||||||
|
break;
|
||||||
|
fi;
|
||||||
|
done<"${BASE_FOLDER}${DATA_ONLY_FILE}";
|
||||||
|
fi;
|
||||||
|
# if nothing is set, default to data
|
||||||
|
if [ -z "${schema_flag}" ]; then
|
||||||
|
SCHEMA_ONLY=''
|
||||||
|
schema_flag="data";
|
||||||
fi;
|
fi;
|
||||||
# Filename
|
# Filename
|
||||||
# Database.User.Encoding.pgsql|data|schema-Version_Host_Port_YearMonthDay_HourMinute_Counter.Fromat(c).sql
|
# Database.User.Encoding.pgsql|data|schema-Version_Host_Port_YearMonthDay_HourMinute_Counter.Fromat(c).sql
|
||||||
|
|||||||
Reference in New Issue
Block a user