PostgreSQL Backup

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stefanwue1968
Posts: 3
Last visit: Tue Feb 07, 2023 3:24 pm

PostgreSQL Backup

Post by stefanwue1968 »

Hallöchen an alle, ich habe ein Problem mit den Parametern zu der pg_dump.exe, der Befehl Sieht so aus der dann in der cmd ausgeführt wird:

C:\Program Files\PostgreSQL\12\bin\pg_dump.exe --file "C:\Backup\Sicherung.backup" --host "localhost" --port "5432" --username "postgres" --no-password --verbose --role "postgres" --format=c --blobs --section=pre-data --section=data --section=post-data --encoding "UTF8" "postgres"

Wie kann ich den Befehl ausführen ? und wie bekomme ich die Ausgabe der CMD in meine Richtextbox ?
Kann mir jemand dabei helfen ?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PostgreSQL Backup

Post by jvierra »

  1. $pgcmd = 'C:\Program Files\PostgreSQL\12\bin\pg_dump.exe --file C:\Backup\Sicherung.backup --host localhost --port 5432 --username postgres --no-password --verbose --role postgres --format=c --blobs --section=pre-data --section=data --section=post-data --encoding UTF8 postgres'
  2. $output =  Invoke-Expression $cmd
User avatar
stefanwue1968
Posts: 3
Last visit: Tue Feb 07, 2023 3:24 pm

Re: PostgreSQL Backup

Post by stefanwue1968 »

Danke für die Antwort, leider funktioniert es so nicht.

Invoke-Expression : Das Argument kann nicht an den Parameter "Command" gebunden werden, da es NULL ist.
In C:\a\post.ps1:77 Zeichen:34
+ $output = Invoke-Expression $cmd <<<< Fehler
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Invoke-Expression], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.InvokeExpre
ssionCommand

was habe ich falsch gemacht ? wie rufe ich den Befehl richtig auf ?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PostgreSQL Backup

Post by jvierra »

Sorry:

$output = Invoke-Expression $pgcmd

I recommend learning PowerShell before trying to write scripts. Your questions are answered in almost all books in the first or second chapter.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: PostgreSQL Backup

Post by Alexander Riedel »

I have to also point out that you will get more answers here if you post in English. You know, this being a U.S. based forum and all :D
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 2 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked