A crazy script using WinSCP and wget to automatically backup PRTG

PRTG is ridiculously hard to automatically backup. Once you read the ridiculously long thread on their forum you are left wondering how mature software could lack such a basic feature. Maybe a menu or two to facilitate the manual work? So that leaves it up for us to figure out the rest.

I created this script to first trigger our backup aggregation monitoring software to get notified of a start backup, do the backup, and then report on the success. It’s not ideal but it works to backup  just the configuration which gives me a little bit of peace of mind.

Prerequisites:

Here is the script:

@echo off

"C:\Program Files (x86)\GnuWin32\bin\wget" -q "https://backup-aggregator.example.com/api/job?api_token=secret&id=2&status=running"

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\Users\Administrator\Desktop\Backup\WinSCP.log" /ini=nul ^
/command ^
"open sftp://backup.vander.host:[email protected]/ -hostkey=""ssh-ed25519_secret""" ^
"lcd ""C:\ProgramData\Paessler\PRTG Network Monitor""" ^
"cd /home/backup-user/backup/prtg2" ^
"put ""PRTG Configuration.dat""" ^
"exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
"C:\Program Files (x86)\GnuWin32\bin\wget" -q "https://backup-aggregator.example.com/api/job?api_token=secret&id=2&status=success"
) else (
echo Error
"C:\Program Files (x86)\GnuWin32\bin\wget" -q ""https://backup-aggregator.example.com/api/job?api_token=secret&id=2&status=error"
)

exit /b %WINSCP_RESULT%

Once you have this going, add it to scheduler like so:

Tags

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top