feat: wrapper for pg_dump

This commit is contained in:
2025-04-22 01:08:28 +00:00
parent dc93bada89
commit 286555e026
3 changed files with 35 additions and 1 deletions

View File

@@ -130,7 +130,8 @@
prettify-log = pkgs.callPackage ./package/prettify-log/default.nix rust.commonArgs; prettify-log = pkgs.callPackage ./package/prettify-log/default.nix rust.commonArgs;
pg-from = pkgs.callPackage ./package/postgres/pg-from/default.nix rust.commonArgs; pg-from = pkgs.callPackage ./package/postgres/pg-from/default.nix rust.commonArgs;
pg-schema = pkgs.callPackage ./package/postgres/pg-schema/default.nix rust.commonArgs; pg-schema = pkgs.callPackage ./package/postgres/pg-schema/default.nix rust.commonArgs;
wpg_dupmall = pkgs.callPackage ./package/postgres/wpg_dupmall.nix rust.commonArgs; pg_wdumpall = pkgs.callPackage ./package/postgres/pg_wdumpall.nix rust.commonArgs;
pg_wdump = pkgs.callPackage ./package/postgres/pg_wdump.nix rust.commonArgs;
pg-migration = pkgs.callPackage ./package/postgres/pg-migration/default.nix rust.commonArgs; pg-migration = pkgs.callPackage ./package/postgres/pg-migration/default.nix rust.commonArgs;
c-hectic = pkgs.callPackage ./package/c/hectic/default.nix {}; c-hectic = pkgs.callPackage ./package/c/hectic/default.nix {};
watch = pkgs.callPackage ./package/c/watch/default.nix {}; watch = pkgs.callPackage ./package/c/watch/default.nix {};

View File

@@ -0,0 +1,33 @@
# Wrapper for pg_dump 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_dump -h "$host" -p "$port" -U "$user" $args
else
exec ${postgresql}/bin/pg_dump $args
fi
''