-
Notifications
You must be signed in to change notification settings - Fork 8
/
backup
executable file
·47 lines (39 loc) · 996 Bytes
/
backup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
set -e
# Backup tools
# this script generates a tgz file with the db dump, app uploads
#
# example: ./backup
# example: ./backup /path/to/your/backup/directory
SOURCE_DIR="."
DEST_DIR=${DEST_DIR:-$SOURCE_DIR}
BACKUP_DIR="$DEST_DIR/backups"
TODAY=`date '+%Y%m%d%H%M%S'`
DEST_FILE=$BACKUP_DIR/`hostname`-$TODAY.tar.gz
mkdir -p $BACKUP_DIR
backup_db () {
echo ""
echo "== Backup db =="
docker exec zealot-postgresql su - postgres -c 'pg_dump -O -Fc zealot -f /tmp/db.dump'
docker cp zealot-postgresql:/tmp/db.dump $BACKUP_DIR
}
backup_zealot () {
echo ""
echo "== Backup zealot data =="
docker cp zealot-zealot:/app/public/uploads $BACKUP_DIR/uploads
}
compress () {
echo ""
echo "== Compress to .tar.gz file =="
tar cvzf $DEST_FILE -X $SOURCE_DIR/.backup-ignore $SOURCE_DIR
}
cleanup () {
echo
echo "== Cleaning up =="
rm -rf $BACKUP_DIR/uploads $BACKUP_DIR/db.dump
}
trap cleanup ERR INT TERM HUP QUIT
backup_db
backup_zealot
compress
cleanup