-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlf_export
executable file
·36 lines (33 loc) · 947 Bytes
/
lf_export
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
#!/bin/sh
if [ -z "$1" -o -z "$2" ]; then
echo "Usage: $0 <dbname> <filename>.sql.gz"
exit 1
fi
EXPORT_DBNAME=liquid_feedback_autoexport
retval=0
echo "Dropping database \"$EXPORT_DBNAME\" if existent..."
dropdb "$EXPORT_DBNAME" 2> /dev/null
echo "Copying database \"$1\" to new database \"$EXPORT_DBNAME\"..."
# TODO: use character encoding of original database
if (createdb "$EXPORT_DBNAME" && pg_dump "$1" | psql -f - "$EXPORT_DBNAME" > /dev/null)
then
echo "Deleting private data in copied database..."
if psql -v ON_ERROR_STOP=1 -c 'SELECT delete_private_data()' "$EXPORT_DBNAME" > /dev/null
then
echo "Dumping and compressing copied database to \"$2\"..."
if pg_dump --no-owner --no-privileges "$EXPORT_DBNAME" | gzip -9 > "$2"
then
true
else
retval=4
fi
else
retval=3
fi
else
retval=2
fi
echo "Dropping database \"$EXPORT_DBNAME\"..."
dropdb "$EXPORT_DBNAME"
echo "DONE."
exit $retval