-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgresql
executable file
·50 lines (37 loc) · 1.29 KB
/
postgresql
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
48
49
#!/bin/bash
# Copyright (C) 2014 Cheli Pineda Ferrer <[email protected]>
#
# http://www.chelipinedaferrer.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
BACKUP_PATH=""
LOG_PATH=""
DATABASES=""
DATE=`date +%G-%m-%d_%H.%M`
HOST=""
PORT=5432
USER=
RECIPIENT=
for DATABASE in $DATABASES
do
FILE_NAME=$DATABASE-$DATE.dmp
pg_dump -U $USER -h $HOST -p $PORT -F c -b -v -f /tmp/$FILE_NAME $DATABASE > $LOG_PATH/$DATABASE-$DATE.log 2> $LOG_PATH/error-$DATABASE-$DATE.log
bzip2 /tmp/$FILE_NAME
if [ $RECIPIENT ]; then
gpg --output $BACKUP_PATH/$FILE_NAME.bz2.gpg --encrypt --recipient $RECIPIENT /tmp/$FILE_NAME.bz2
rm /tmp/$FILE_NAME.bz2
else
mv /tmp/$FILE_NAME.bz2 $BACKUP_PATH
fi
done;