Skip to content

Commit

Permalink
Merge pull request #40 from Simonefardella/master
Browse files Browse the repository at this point in the history
Dockerfile updates and some small optimization
  • Loading branch information
rsoika authored Jan 22, 2020
2 parents 3ab6f6e + 8c1e052 commit 5ee204e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 21 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ This project provide various Docker images used by the Imixs-Workflow project
* [imixs/backup](backup/README.md) - a backup service to backup or restore the data of an Imixs-Workflow instance
* [imixs/smarthost](exim4/README.md) - a exim4 smarthost
* [imixs/hadoop](hadoop/README.md) - a hadoop single node cluster for testing
* [imixs/postgres](postgres/README.md) - a backup service to backup or restore the data of an PostgreSql instance
* [imixs/tika](tika/README.md) - a service that provides a Tika Server. This server can be used for OCR via a Rest API provided by the Apache Tika Project
* [imixs/exim4](exim4/README.md) - a service that provides a mail transfer agent (MTA) running as a smarthost for Docker containers. The container can be used to send out e-mails from other containers.
6 changes: 3 additions & 3 deletions backup/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM debian:stretch
FROM debian:buster-slim

MAINTAINER Ralph Soika <ralph.soika@imixs.com>
LABEL authors="Ralph Soika <ralph.soika@imixs.com>, Simone Fardella <fardella.simone@gmail.com>"

# install packages: psql and slim down image
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
cron ssh mysql-client postgresql-client \
cron ssh mariadb-client postgresql-client-11 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/man/?? /usr/share/man/??_*

Expand Down
15 changes: 9 additions & 6 deletions backup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The service is designed to backup only one database. In case you want to use thi
* restore feature.

## Environment
The imixs/backup image is based on the [official postgres image](https://hub.docker.com/_/postgres/) with additional mysql-client support.
The imixs/backup image is based on the [official postgres image](https://hub.docker.com/_/postgres/) with additional mariadb-client support.

imixs/backup provides the following environment variables which need to be set during container startup:

Expand All @@ -32,15 +32,15 @@ imixs/backup provides the following environment variables which need to be set d
* BACKUP\_SPACE\_USER - backup space user
* BACKUP\_LOCAL\_ROLLING - number of backup files to be kept locally
* BACKUP\_SPACE\_ROLLING - number of backup files to be kept in the backup space

* BACKUP\_ROOT\_DIR - backup root directory (e.g. "/imixs-cloud", default if not set will be "/imixs-cloud")

All backups are located in the following local directory

/root/backups/

In the backup space, the files are located at:

/imixs-cloud/$BACKUP_SERVICE_NAME/
/$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/

Each backup file has a time stamp prefix indicating the backup time:

Expand Down Expand Up @@ -80,10 +80,12 @@ The backup script automatically holds a number of backup files locally. The defa
In case the optional environment variable "BACKUP\_SPACE\_HOST" is provided, the service will push backup files automatically into a backup space via SFTP/SCP.
The backup directory on the backup space is

/imixs-cloud/$BACKUP_SERVICE_NAME/....
/$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/....

The optional environment variable "BACKUP\_SERVICE\_NAME" can be set to name the backup directory on the backup space. If no service name is set, the docker container ID will be used instead.

In case the optional environment variable "BACKUP\_SPACE\_HOST" is provided, the environment variable "BACKUP\_ROOT\_DIR" can be set to name the backup directory on the backup space, otherwise it will be used the default "/imixs-cloud" folder.

#### Create a SSH Key

To transfers files to the backup space this service uses SFTP/SCP. For this reason a RFC4716 Public Key need to be provided on the backup space.
Expand Down Expand Up @@ -155,6 +157,7 @@ If you add a backup space the following optional environment settings are needed
BACKUP_SPACE_HOST: "my-backup.org"
BACKUP_SPACE_USER: "yyyy"
BACKUP_SPACE_KEY_FILE: "/run/secrets/backupspace_key"
BACKUP_ROOT_DIR: "/imixs-cloud"
....

If you want to backup file directories form a mounted volume:
Expand Down Expand Up @@ -230,11 +233,11 @@ In case you have no local backup files available, you can pull a backup file fir

Run the following command to get a list of all backup files available on the backupspace:

echo ls -la /imixs-cloud/$BACKUP_SERVICE_NAME | sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST
echo ls -la /$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME | sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST

You can pull a specific backup file with the script backup_get.sh followed by the filename:

/root/backup_get.sh /imixs-cloud/$BACKUP_SERVICE_NAME/[BACKUPFILE]
/root/backup_get.sh /$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/[BACKUPFILE]


The remote backupfile will be written to the directory /root/backups/. Now you can restore the backup as explained before.
Expand Down
14 changes: 11 additions & 3 deletions backup/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ if [ "$BACKUPS_EXIST_LOCAL" -gt "$BACKUP_LOCAL_ROLLING" ]
ls -F /root/backups/*_dump.tar.gz | head -n -$BACKUP_LOCAL_ROLLING | xargs rm
fi

if [ "$BACKUP_ROOT_DIR" == "" ]
then
# If the Backup root dir is not specified, it will use the default /imixs-cloud...
echo "*** ...Environment variable BACKUP_ROOT_DIR not set, using default /imixs-cloud folder..."

BACKUP_ROOT_DIR="/imixs-cloud"
fi


# ****************************************************
# Copy Backup Files into the Backup Space
Expand All @@ -130,7 +138,7 @@ if [ "$BACKUP_SPACE_HOST" != "" ]
echo "*** ...upload to backup space..."

sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST > /dev/null << SFTPEOF
cd /imixs-cloud/$BACKUP_SERVICE_NAME/
cd /$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/
put $BACKUP_FILE
quit
SFTPEOF
Expand All @@ -141,12 +149,12 @@ SFTPEOF
# ****************************************************

# first we count the existing backup files in the backup space
BACKUPS_EXIST_SPACE=$(echo ls -l /imixs-cloud/$BACKUP_SERVICE_NAME/*_dump.tar.gz | sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST | grep -v ^l | wc -l)
BACKUPS_EXIST_SPACE=$(echo ls -l /$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/*_dump.tar.gz | sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST | grep -v ^l | wc -l)
# now we remove the files if we have more than defined BACKUP_SPACE_ROLLING...
if [ "$BACKUPS_EXIST_SPACE" -gt "$BACKUP_SPACE_ROLLING" ]
then
# get a list of all dump files (tricky command because ls -t does not work)...
RESULT=`echo "ls /imixs-cloud/$BACKUP_SERVICE_NAME/*_dump.*" | sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST | grep .tar.gz | sort -Vr`
RESULT=`echo "ls /$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/*_dump.*" | sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST | grep .tar.gz | sort -Vr`

# remove the deprecated backup files...
i=0
Expand Down
13 changes: 10 additions & 3 deletions backup/backup_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ echo "user=$BACKUP_DB_USER" >> ~/.my.cnf
echo "password=$BACKUP_DB_PASSWORD" >> ~/.my.cnf
chmod 0600 ~/.my.cnf

if [ "$BACKUP_ROOT_DIR" == "" ]
then
# If the Backup root dir is not specified, it will use the default /imixs-cloud...
echo "*** ...Environment variable BACKUP_ROOT_DIR not set, using default /imixs-cloud folder..."

BACKUP_ROOT_DIR="/imixs-cloud"
fi

# copy the ssh key for backup space if defined...
if [ -f /run/secrets/backupspace_key ]
Expand All @@ -58,11 +65,11 @@ then
echo "Host *" >> /root/.ssh/config
echo " StrictHostKeyChecking no" >> /root/.ssh/config
chmod 400 /root/.ssh/config

# create the target dir....
sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST << SFTPEOF
mkdir /imixs-cloud
mkdir /imixs-cloud/$BACKUP_SERVICE_NAME/
mkdir /$BACKUP_ROOT_DIR
mkdir /$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/
quit
SFTPEOF

Expand Down
2 changes: 1 addition & 1 deletion postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM postgres:11.2

MAINTAINER Ralph Soika <ralph.soika@imixs.com>
LABEL authors="Ralph Soika <ralph.soika@imixs.com>, Simone Fardella <fardella.simone@gmail.com>"

# install packages: psql and slim down image
RUN apt-get update \
Expand Down
11 changes: 9 additions & 2 deletions postgres/docker-entrypoint-initdb.d/backup_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ echo "user=$BACKUP_DB_USER" >> ~/.my.cnf
echo "password=$BACKUP_DB_PASSWORD" >> ~/.my.cnf
chmod 0600 ~/.my.cnf

if [ "$BACKUP_ROOT_DIR" == "" ]
then
# If the Backup root dir is not specified, it will use the default /imixs-cloud...
echo "*** ...Environment variable BACKUP_ROOT_DIR not set, using default /imixs-cloud folder..."

BACKUP_ROOT_DIR="/imixs-cloud"
fi

# copy the ssh key for backup space if defined...
if [ -f /run/secrets/backupspace_key ]
Expand All @@ -61,8 +68,8 @@ then

# create the target dir....
sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST << SFTPEOF
mkdir /imixs-cloud
mkdir /imixs-cloud/$BACKUP_SERVICE_NAME/
mkdir /$BACKUP_ROOT_DIR
mkdir /$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/
quit
SFTPEOF

Expand Down
13 changes: 10 additions & 3 deletions postgres/scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ if [ "$BACKUPS_EXIST_LOCAL" -gt "$BACKUP_LOCAL_ROLLING" ]
ls -F /root/backups/*_dump.tar.gz | head -n -$BACKUP_LOCAL_ROLLING | xargs rm
fi

if [ "$BACKUP_ROOT_DIR" == "" ]
then
# If the Backup root dir is not specified, it will use the default /imixs-cloud...
echo "*** ...Environment variable BACKUP_ROOT_DIR not set, using default /imixs-cloud folder..."

BACKUP_ROOT_DIR="/imixs-cloud"
fi

# ****************************************************
# Copy Backup Files into the Backup Space
Expand All @@ -130,7 +137,7 @@ if [ "$BACKUP_SPACE_HOST" != "" ]
echo "*** ...upload to backup space..."

sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST > /dev/null << SFTPEOF
cd /imixs-cloud/$BACKUP_SERVICE_NAME/
cd /$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/
put $BACKUP_FILE
quit
SFTPEOF
Expand All @@ -141,12 +148,12 @@ SFTPEOF
# ****************************************************

# first we count the existing backup files in the backup space
BACKUPS_EXIST_SPACE=$(echo ls -l /imixs-cloud/$BACKUP_SERVICE_NAME/*_dump.tar.gz | sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST | grep -v ^l | wc -l)
BACKUPS_EXIST_SPACE=$(echo ls -l /$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/*_dump.tar.gz | sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST | grep -v ^l | wc -l)
# now we remove the files if we have more than defined BACKUP_SPACE_ROLLING...
if [ "$BACKUPS_EXIST_SPACE" -gt "$BACKUP_SPACE_ROLLING" ]
then
# get a list of all dump files (tricky command because ls -t does not work)...
RESULT=`echo "ls /imixs-cloud/$BACKUP_SERVICE_NAME/*_dump.*" | sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST | grep .tar.gz | sort -Vr`
RESULT=`echo "ls /$BACKUP_ROOT_DIR/$BACKUP_SERVICE_NAME/*_dump.*" | sftp $BACKUP_SPACE_USER@$BACKUP_SPACE_HOST | grep .tar.gz | sort -Vr`

# remove the deprecated backup files...
i=0
Expand Down

0 comments on commit 5ee204e

Please sign in to comment.