feat: wrapper for pg_dumpall
This commit is contained in:
33
package/postgres/wpg_dupmall.nix
Normal file
33
package/postgres/wpg_dupmall.nix
Normal file
@@ -0,0 +1,33 @@
|
||||
# Wrapper for pg_dumpall with url option
|
||||
{ writeShellScriptBin, postgresql, ... }:
|
||||
writeShellScriptBin "wpg_dupmall" /* */ ''
|
||||
#!/bin/sh
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--url=*)
|
||||
url="''${1#--url=}"
|
||||
shift
|
||||
;;
|
||||
--url)
|
||||
url="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
args="$args $1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -n "$url" ]; then
|
||||
user=$(echo "$url" | sed -E 's|.*://([^:]+):.*@.*|\1|')
|
||||
pass=$(echo "$url" | sed -E 's|.*://[^:]+:([^@]+)@.*|\1|')
|
||||
host=$(echo "$url" | sed -E 's|.*@([^:/]+):.*|\1|')
|
||||
port=$(echo "$url" | sed -E 's|.*:([0-9]+)/?.*|\1|')
|
||||
export PGPASSWORD="$pass"
|
||||
exec ${postgresql}/bin/pg_dumpall -h "$host" -p "$port" -U "$user" $args
|
||||
else
|
||||
exec ${postgresql}/bin/pg_dumpall $args
|
||||
fi
|
||||
''
|
||||
Reference in New Issue
Block a user