Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa77876440 | ||
|
|
f128b7ebc4 | ||
|
|
77977207c8 | ||
|
|
c1f6bb443a | ||
|
|
86b0fa122a | ||
|
|
32c320be27 | ||
|
|
500ab01790 | ||
|
|
ab58ab3ad0 | ||
|
|
7767eb58df | ||
|
|
38f467de96 | ||
|
|
8f91690f6a | ||
|
|
e860573e0c | ||
|
|
f990e86949 | ||
|
|
c929987900 | ||
|
|
6cb941818c | ||
|
|
edaf41f1af | ||
|
|
c7f2197614 | ||
|
|
88ea600e1d | ||
|
|
f396032728 | ||
|
|
18cbcea2b0 | ||
|
|
a0537a24d3 | ||
|
|
89897eb676 |
@@ -8,14 +8,20 @@
|
||||
# pgsql
|
||||
# zabbix-settings-
|
||||
|
||||
export BORG_BASE_DIR="borg/";
|
||||
# debug and dry run
|
||||
DEBUG=0;
|
||||
DRYRUN=0;
|
||||
PGSQL_SUDO=1;
|
||||
# options
|
||||
OPT_REMOTE="";
|
||||
PGSQL_SUDO_USER="postgres";
|
||||
# basic settings needed
|
||||
TARGET_USER="";
|
||||
TARGET_HOST="";
|
||||
TARGET_PORT="";
|
||||
TARGET_BORG_PATH="";
|
||||
TARGET_FOLDER="";
|
||||
# base folder
|
||||
BASE_FOLDER="/usr/local/scripts/borg/";
|
||||
# those are the valid modules
|
||||
MODULE_LIST="file gitea mysql pgsql zabbix"
|
||||
@@ -23,10 +29,13 @@ MODULE_LIST="file gitea mysql pgsql zabbix"
|
||||
# basic options
|
||||
# -c for config file override
|
||||
# -n for dry run test
|
||||
while getopts ":c:nd" opt; do
|
||||
while getopts ":c:snd" opt; do
|
||||
case "${opt}" in
|
||||
c|config)
|
||||
BASE_FOLDER=${OPTARG}"/";
|
||||
BASE_FOLDER=${OPTARG};
|
||||
;;
|
||||
s|nosudo)
|
||||
PGSQL_SUDO=0;
|
||||
;;
|
||||
d|debug)
|
||||
DEBUG=1;
|
||||
@@ -56,6 +65,14 @@ if [ ! -f "${BASE_FOLDER}${SETTINGS_FILE}" ]; then
|
||||
exit;
|
||||
fi;
|
||||
. "${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};
|
||||
for MODULE in ${MODULE_LIST}; do
|
||||
echo "************* MODULE: ${MODULE}";
|
||||
@@ -79,23 +96,43 @@ for MODULE in ${MODULE_LIST}; do
|
||||
fi;
|
||||
# we dont allow special characters, so we don't need to special escape it
|
||||
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}";
|
||||
borg list --format '{archive}{NL}' ${REPOSITORY}|grep -v "${MODULE},"|
|
||||
borg list ${OPT_REMOTE} --format '{archive}{NL}' ${REPOSITORY}|grep -v "${MODULE},"|
|
||||
while read i; do
|
||||
# for gitea, zabbix we do not ADD we RENAME
|
||||
if [ "${MODILE}" = "gitea" ]; then
|
||||
target_name=$(echo $i | sed -e 's/gitea-/gitea,/');
|
||||
elif [ "${MODILE}" = "zabbix" ]; then
|
||||
target_name=$(echo $i | sed -e 's/zabbix-settings-/zabbix,settings-/');
|
||||
if [ "${MODULE}" = "gitea" ]; then
|
||||
# if just date, add gitea,
|
||||
# else rename
|
||||
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
|
||||
target_name="${MODULE},${i}";
|
||||
fi;
|
||||
echo "- Rename from: ${i} to: ${target_name}";
|
||||
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;
|
||||
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;
|
||||
done;
|
||||
done;
|
||||
|
||||
@@ -139,6 +139,8 @@ KEEP_INFO="";
|
||||
# override standard keep for tagged backups
|
||||
if [ ! -z "${ONE_TIME_TAG}" ]; then
|
||||
BACKUP_SET="{now:%Y-%m-%dT%H:%M:%S}";
|
||||
# set empty to avoid problems
|
||||
KEEP_OPTIONS=("");
|
||||
else
|
||||
# build options and info string,
|
||||
# also flag BACKUP_SET check if hourly is set
|
||||
@@ -182,7 +184,7 @@ else
|
||||
fi;
|
||||
fi;
|
||||
# abort if KEEP_OPTIONS is empty
|
||||
if [ -z "${KEEP_OPTIONS}" ]; then
|
||||
if [ "${#KEEP_OPTIONS[@]}" -eq "0" ]; then
|
||||
echo "[! $(date +'%F %T')] It seems no KEEP_* entries where set in a valid format.";
|
||||
exit 1;
|
||||
fi;
|
||||
@@ -197,7 +199,6 @@ else
|
||||
fi;
|
||||
fi;
|
||||
|
||||
|
||||
# for folders list split set to "#" and keep the old setting as is
|
||||
_IFS=${IFS};
|
||||
IFS="#";
|
||||
@@ -304,14 +305,14 @@ fi;
|
||||
# PRINT OUT current data, only do this if REPO exists
|
||||
if [ ${PRINT} -eq 1 ]; then
|
||||
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
|
||||
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then
|
||||
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${BORG_COMMAND} list ${OPT_REMOTE} --format ${FORMAT} ${REPOSITORY}";
|
||||
fi;
|
||||
# run info command if not a dry drun
|
||||
if [ ${DRYRUN} -eq 0 ]; then
|
||||
borg list ${OPT_REMOTE} --format "${FORMAT}" ${REPOSITORY} ;
|
||||
${BORG_COMMAND} list ${OPT_REMOTE} --format "${FORMAT}" ${REPOSITORY} ;
|
||||
fi;
|
||||
if [ ${VERBOSE} -eq 1 ]; then
|
||||
echo "";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# unset borg settings
|
||||
unset BORG_BASE_DIR BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK BORG_RELOCATED_REPO_ACCESS_IS_OK
|
||||
# error abort without duration and error notice
|
||||
if [ $1 == 1 ]; then
|
||||
if [ $# -ge 1 ] && [ "$1" = "1" ]; then
|
||||
echo "=== [ERROR: $(date +'%F %T')] ==[${MODULE}]====================================>";
|
||||
else
|
||||
DURATION=$[ $(date +'%s')-$START ];
|
||||
|
||||
@@ -19,7 +19,7 @@ function version {
|
||||
}
|
||||
|
||||
# version for all general files
|
||||
VERSION="4.1.2";
|
||||
VERSION="4.2.4";
|
||||
|
||||
# borg version and borg comamnd
|
||||
BORG_VERSION="";
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
# set last edit date + time
|
||||
MODULE="pgsql"
|
||||
MODULE_VERSION="1.1.1";
|
||||
MODULE_VERSION="1.2.0";
|
||||
|
||||
|
||||
DIR="${BASH_SOURCE%/*}"
|
||||
@@ -22,6 +22,7 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||
INCLUDE_FILE="borg.backup.pgsql.include";
|
||||
EXCLUDE_FILE="borg.backup.pgsql.exclude";
|
||||
SCHEMA_ONLY_FILE="borg.backup.pgsql.schema-only";
|
||||
DATA_ONLY_FILE="borg.backup.pgsql.data-only";
|
||||
# init check file
|
||||
BACKUP_INIT_CHECK="borg.backup.pgsql.init";
|
||||
|
||||
@@ -195,9 +196,13 @@ else
|
||||
fi;
|
||||
if [ ${include} -eq 1 ] && [ ${exclude} -eq 0 ]; then
|
||||
# set dump type
|
||||
SCHEMA_ONLY=''; # empty for all
|
||||
schema_flag='data'; # or data
|
||||
SCHEMA_ONLY='';
|
||||
schema_flag=''; # schema or data
|
||||
# schema exclude over data exclude, can't have both
|
||||
if [ -s "${BASE_FOLDER}${SCHEMA_ONLY_FILE}" ]; then
|
||||
# default is data dump
|
||||
SCHEMA_ONLY='';
|
||||
schema_flag='data';
|
||||
while read schema_db; do
|
||||
if [ "${db}" = "${schema_db}" ]; then
|
||||
SCHEMA_ONLY='-s';
|
||||
@@ -206,6 +211,23 @@ else
|
||||
break;
|
||||
fi;
|
||||
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;
|
||||
# Filename
|
||||
# Database.User.Encoding.pgsql|data|schema-Version_Host_Port_YearMonthDay_HourMinute_Counter.Fromat(c).sql
|
||||
|
||||
Reference in New Issue
Block a user