forked from kartoza/docker-pg-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
docker build -t kartoza/pg-backups . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|