-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg-export.sh
More file actions
47 lines (43 loc) · 825 Bytes
/
pg-export.sh
File metadata and controls
47 lines (43 loc) · 825 Bytes
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
function showHelp() {
echo "Available options :"
echo "-d | --db-name Database name in postgresql"
echo "-o | --output Output name (with .sql)"
echo "-h | --help Show help"
}
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
case $1 in
-d | --db-name)
shift
db=$1
;;
-o | --output)
shift
output=$1
;;
-h | --help)
showHelp
exit 1
;;
*)
echo "Invalid option $1"
showHelp
exit 1
;;
esac
shift
done
if [[ "$1" == '--' ]]; then shift; fi
if [[ -z $db ]]; then
echo "Database can't be empty!"
showHelp
exit
fi
if [[ -z $output ]]; then
echo "Output can't be empty!"
showHelp
exit
fi
echo "Exporting database $db to $output"
pg_dump -U postgres -h localhost $db >> $output
echo "Export has finished"
echo "Exported database located at: $(pwd)/$output"