blob: aa6f5b6a6d2431ebe63eebe4e12a29620952bdd7 [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
---
apiVersion: v1
kind: ConfigMap
metadata:
name: base-kubegres-backup-config
namespace: nuvolaris
data:
backup_database.sh: |
#!/bin/bash
set -e
dt=$(date '+%d/%m/%Y %H:%M:%S');
fileDt=$(date '+%d_%m_%Y_%H_%M_%S');
backUpFileName="$KUBEGRES_RESOURCE_NAME-backup-$fileDt.gz"
backUpFilePath="$BACKUP_DESTINATION_FOLDER/$backUpFileName"
echo "$dt - Starting DB backup of Kubegres resource $KUBEGRES_RESOURCE_NAME into file: $backUpFilePath";
echo "$dt - Running: pg_dumpall -h $BACKUP_SOURCE_DB_HOST_NAME -U postgres -c | gzip > $backUpFilePath"
pg_dumpall -h $BACKUP_SOURCE_DB_HOST_NAME -U postgres -c | gzip > $backUpFilePath
if [ $? -ne 0 ]; then
rm $backUpFilePath
echo "Unable to execute a BackUp. Please check DB connection settings"
exit 1
fi
find $BACKUP_DESTINATION_FOLDER -type f -mtime +1 -name '*.gz' -execdir rm -- '{}' \;
echo "$dt - DB backup completed for Kubegres resource $KUBEGRES_RESOURCE_NAME into file: $backUpFilePath";
backup_start.sh: |
#!/bin/bash
set -e
dt=$(date '+%d/%m/%Y %H:%M:%S');
set -m
# Start the helper processes
# service rsyslog start
service cron start
echo "$dt - Scheduling: $BACKUP_SCHEDULE /tmp/backup_database.sh"
(crontab -l 2>/dev/null || true; echo "$BACKUP_SCHEDULE export KUBEGRES_RESOURCE_NAME=$KUBEGRES_RESOURCE_NAME; export BACKUP_DESTINATION_FOLDER=$BACKUP_DESTINATION_FOLDER; export BACKUP_SOURCE_DB_HOST_NAME=$BACKUP_SOURCE_DB_HOST_NAME; export PGPASSWORD=$PGPASSWORD; /tmp/backup_database.sh /dev/stdout 2>&1;") | crontab -
while true; do sleep 60; done;