[Powershell] Restic doesn't output any text in powershell window

Hello. So i’ve set up basic powershell script that basically backup some drives based on included and excluded files. Here is the script

restic -r \\192.168.1.72\Backups\restic\toto_pc backup --files-from-verbatim "D:\Program Files\restic\include.txt" --iexclude-file "D:\Program Files\restic\exclude.txt" | Out-File -FilePath "D:\Program Files\restic\logs\stdout_$(get-date -f yyyy-MM-dd).log" -encoding ascii
pause

So it should do what i basically described. The issue is restic shows only text to enter password “enter password for repository:” and when i enter it, it shows nothing expect some errors that access is denied to that folders. At first i thought it is caused by --quiet flag so it wouldn’t output any text but i removed that flag and it does the same thing.

Any idea how to fix this?

Update: So the files are backedup now but i have still double output issue. Some of the info is present in log file that i entered like so:
image

But some of the text - mostly errors kept themselfs only in powershell window:

Any ideas how to unify output to only the text file and also ideally hide the powershell window so it can do it’s job quietly in the background?

I don’t know particularly much about powershell, but a pipe | probably just redirects stdout to the following command, which appears to just store the output in a file, but does not print it on the terminal. That is the reason why the output is not visible on the terminal.

The remaining output is printed on stderr, which is not redirected with the command you’re currently using. So you’ll have to add some option to redirect stderr to stdout, maybe 2>&1 also works for Powershell, but I have no clue what the correct syntax is.

For hiding the powershell window, there are probably lots of tutorials available on the internet.

2 Likes

This works for me with powershell, 2> is the standard error file descriptor. The | (pipe) only gets the standard output.
I do not know how to run powershell without opening up a window.
.${RESTICEXE} backup -r $RESTIC_REPOSITORY --iexclude-file $RESTIC_IEXCLUDE_FILE --use-fs-snapshot --verbose --verbose --cache-dir $CACHEDIR --json ${RESTIC_SOURCE_DRIVE}:\ –compression $RESTIC_COMPRESSION_LEVEL 2>$RESTIC_STDERR_FILE | Out-File -FilePath .\restic_temp_stdout.log -encoding ascii
Note the use of --use-fs-snapshot
Of course, the variables have to be set before the command is run.
Hope this helps.

Any ideas how to unify output to only the text file and also ideally hide the powershell window so it can do it’s job quietly in the background?

A few ideas on hiding the window: How to run a PowerShell script without displaying a window? - Stack Overflow

I tend to use scheduled tasks with “Run whether user is logged in or not”, but there are various approaches you can use.