Skip to content

Commit

Permalink
Various fixes for backup reigieme
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Apr 16, 2015
1 parent 8c6f0c9 commit 1e1f4ff
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ 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
ADD start.sh /start.sh

CMD cron -f
CMD ["/start.sh"]
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

A simple docker container that runs PostGIS backups. It is intended to be used
primarily with our [docker postgis](https://github.com/kartoza/docker-postgis)
docker image. By default it will create a backup once per night in a nicely
ordered directory by year / month.
docker image. By default it will create a backup once per night (at 23h00)in a
nicely ordered directory by year / month.

Visit our page on the docker hub at: https://github.com/kartoza/docker-pg-backup

Expand Down Expand Up @@ -41,12 +41,17 @@ git clone git://github.com/kartoza/docker-postgis
To create a running container do:

```
docker run --name="backups" --hostname="pg-backups" -link db -i -d kartoza/pg-backups
```
docker run --name="backups"\
--hostname="pg-backups" \
--link=watchkeeper_db_1:db \
-v backups:/backups \
-i -d kartoza/pg-backups```
In this example I used a volume into which the actual backups will be
stored.
# Specifying environment
**Note:** This is not implemented yet:
You can also use the following environment variables to pass a
user name and password etc for the database connection.
Expand All @@ -65,6 +70,21 @@ Example usage:
docker run -e PGUSER=bob -e PGPASSWORD=secret -link db -i -d kartoza/pg-backups
```
One other environment variable you may like to set is a prefix for the
database dumps.
Variable | Expected | Default if not specified
---------|----------|--------------------------
DUMPPREFIX | <text> | PG_
Example usage:
```
docker run -e DUMPPREFIX=foo -link db -i -d kartoza/pg-backups
```
## Credits
Expand Down
3 changes: 2 additions & 1 deletion backups-cron
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*/10 * * * * root /backups.sh 2>&1
# Run the backups at 11pm each night
*/1 * * * * root /backups.sh 2>&1
# We need a blank line here for it to be a valid cron file
17 changes: 11 additions & 6 deletions backups.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#!/bin/bash

source /pgenv.sh

#echo "Running with these environment options" >> /var/log/cron.log
#set | grep PG >> /var/log/cron.log

MYDATE=`date +%d-%B-%Y`
MONTH=$(date +%B)
YEAR=$(date +%Y)
MYBASEDIR=/backups
MYBACKUPDIR=${MYBASEDIR}/${YEAR}/${MONTH}
mkdir -p $MYBACKUPDIR
cd $MYBACKUPDIR
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 ":"`
DBLIST=`psql -l | awk '{print $1}' | grep -v "+" | grep -v "Name" | grep -v "List" | grep -v "(" | grep -v "template" | grep -v "postgres" | grep -v "|" | grep -v ":"`
# echo "Databases to backup: ${DBLIST}" >> /var/log/cron.log
for DB in ${DBLIST}
do
echo "Backing up $DB"
FILENAME=${MYBACKUPDIR}/PG_${DB}.${MYDATE}.dmp
pg_dump -i -Fc -f ${FILENAME} -x -O ${DB}"
echo "Backing up $DB" >> /var/log/cron.log
FILENAME=${MYBACKUPDIR}/${DUMPPREFIX}_${DB}.${MYDATE}.dmp
pg_dump -i -Fc -f ${FILENAME} -x -O ${DB}
done
6 changes: 5 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash

docker run --name="backups" --hostname="pg-backups" -link db -i -d kartoza/pg-backups
docker run --name="backups"\
--hostname="pg-backups" \
--link=watchkeeper_db_1:db \
-v /Users/timlinux/backups:/backups \
-i -d kartoza/pg-backups

0 comments on commit 1e1f4ff

Please sign in to comment.