|
@@ -9,14 +9,27 @@ if [ -z "${LOCAL_DIR}" ]; then
|
|
|
exit 1;
|
|
|
fi
|
|
|
|
|
|
-if [ -z "${REMOTE_USER}" ]; then
|
|
|
- echo >&2 "REMOTE_USER is not set. Aborting.";
|
|
|
+if [ -z "${REMOTE_ENABLE}" ]; then
|
|
|
+
|
|
|
+ echo >&2 "REMOTE_ENABLE is not set. Aborting.";
|
|
|
exit 1;
|
|
|
+
|
|
|
+elif [ ${REMOTE_ENABLE} = true ]; then
|
|
|
+
|
|
|
+ if [ -z "${REMOTE_USER}" ]; then
|
|
|
+ echo >&2 "REMOTE_USER is not set. Aborting.";
|
|
|
+ exit 1;
|
|
|
+ fi
|
|
|
+
|
|
|
+ if [ -z "${REMOTE_HOSTNAME}" ]; then
|
|
|
+ echo >&2 "REMOTE_HOSTNAME is not set. Aborting.";
|
|
|
+ exit 1;
|
|
|
+ fi
|
|
|
+
|
|
|
fi
|
|
|
|
|
|
-if [ -z "${REMOTE_HOSTNAME}" ]; then
|
|
|
- echo >&2 "REMOTE_HOSTNAME is not set. Aborting.";
|
|
|
- exit 1;
|
|
|
+if [ -z "${PGSQL_EXCLUDE_DATNAME}" ]; then
|
|
|
+ PGSQL_EXCLUDE_DATNAME="['template_']"
|
|
|
fi
|
|
|
|
|
|
HOSTNAME=`hostname`
|
|
@@ -50,7 +63,7 @@ fi
|
|
|
# Backup PostgreSQL data if pg_dump is available, and user postgres exists
|
|
|
if type "pg_dump" > /dev/null; then
|
|
|
if id -u "postgres" > /dev/null 2>&1; then
|
|
|
- PG_DBS=`sudo -i -u postgres psql template1 -t -c "SELECT datname FROM pg_database WHERE datname NOT LIKE 'template_'"`
|
|
|
+ PG_DBS=`sudo -i -u postgres psql template1 -t -c "SELECT datname FROM pg_database WHERE NOT datname LIKE ANY(ARRAY${PGSQL_EXCLUDE_DATNAME})"`
|
|
|
for PG_DB in $PG_DBS
|
|
|
do
|
|
|
PG_BACKUP=`sudo -u postgres mktemp -t pg_dump_XXXX`
|
|
@@ -71,15 +84,19 @@ borg create --exclude-from /etc/fcn-toolbox/backup.exclude ${BACKUP_DEST}::${BAC
|
|
|
# Prune local archives to keep only 7 daily, and 4 weekly, and 3 monthly ones
|
|
|
borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=3 ${BACKUP_DEST}
|
|
|
|
|
|
-# Quick check of the remote repository before doing a remote backup
|
|
|
-if borg check --repository-only ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}; then
|
|
|
- # Do remote backup
|
|
|
- borg create --exclude-from /etc/fcn-toolbox/backup.exclude ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}::${BACKUP_NAME} "/etc" "${BACKUP_TEMP}"
|
|
|
- # Prune remote archives to keep only 7 daily, and 4 weekly, and 3 monthly ones
|
|
|
- borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=3 ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}
|
|
|
-else
|
|
|
- echo >&2 "Remote repository is missing of corrupted. Try running: "
|
|
|
- echo >&2 "borg init --encryption=none ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}"
|
|
|
+if [ ${REMOTE_ENABLE} = true ]; then
|
|
|
+
|
|
|
+ # Quick check of the remote repository before doing a remote backup
|
|
|
+ if borg check --repository-only ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}; then
|
|
|
+ # Do remote backup
|
|
|
+ borg create --exclude-from /etc/fcn-toolbox/backup.exclude ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}::${BACKUP_NAME} "/etc" "${BACKUP_TEMP}"
|
|
|
+ # Prune remote archives to keep only 7 daily, and 4 weekly, and 3 monthly ones
|
|
|
+ borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=3 ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}
|
|
|
+ else
|
|
|
+ echo >&2 "Remote repository is missing of corrupted. Try running: "
|
|
|
+ echo >&2 "borg init --encryption=none ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}"
|
|
|
+ fi
|
|
|
+
|
|
|
fi
|
|
|
|
|
|
# Delete temporary directory
|