Skip to content

Commit

Permalink
Initial setup of repo
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Apr 16, 2015
1 parent e3ad631 commit 9c17001
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ubuntu:latest
MAINTAINER [email protected]

RUN apt-get install -y postgresql-client
ADD backups-cron /etc/cron.d/backups-cron
RUN touch /var/log/cron.log
ADD backups.sh /backups.sh

CMD cron -f
2 changes: 2 additions & 0 deletions backups-cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*/10 * * * * root /backups.sh 2>&1
# We need a blank line here for it to be a valid cron file
24 changes: 24 additions & 0 deletions backups.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash


MYDATE=`date +%d-%B-%Y`
MONTH=$(date +%B)
YEAR=$(date +%Y)
MYBASEDIR=/backups
MYBACKUPDIR=${MYBASEDIR}/${YEAR}/${MONTH}
mkdir -p $MYBACKUPDIR
cd $MYBACKUPDIR

echo "Backup running to $MYBACKUPDIR" >> /var/log/cron.log

#
# Loop through each pg database backing it up
#

DBLIST=`psql -l | awk '{print $1}' | grep -v "+" | grep -v "Name" | grep -v "List" | grep -v "(" | grep -v "template" | grep -v "postgres" | grep -v ":"`
for DB in ${DBLIST}
do
echo "Backing up $DB"
FILENAME=${MYBACKUPDIR}/PG_${DB}.${MYDATE}.dmp
pg_dump -i -Fc -f ${FILENAME} -x -O ${DB}"
done
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker build -t kartoza/pg-backups .
4 changes: 4 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

docker run --name="cron" --hostname="cron" -link watchkeeper_db_1 -i -d kartoza/pg-backups

0 comments on commit 9c17001

Please sign in to comment.