A crazy script using WinSCP and wget on Windows to automatically backup PRTG Configuration

Background

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:

  • A backup server with SSH/SFTP access
    • Ideally this server is protected by keys instead of passwords. This makes the setup more complicated but infinitely more secure.
  • GNU Win32 Wget
    • https://gnuwin32.sourceforge.net/packages/wget.htm
  • WinSCP
    • To generate the SSH key, you can launch PuTTY Key Generator from the New Session/Tools menu of a new Login dialog
    • Create a Log directory, e.g. Desktop/Backup

The backup of the configuration on a small system (100 sensors) is around 6MB.

The Script

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-user:[email protected]/ -hostkey=""ssh-ed25519_secret""" ^
"lcd ""C:\ProgramData\Paessler\PRTG Network Monitor""" ^
"cd /home/backup-user/backup/prtg_backup" ^
"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%

Adding a Scheduled Job

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

Task Scheduler / Create Task

Name: Backup PRTG

Run whether user is logged on or not

Triggers Tab: Daily at 4AM

Actions / New / Start a program

Be sure to add it item below in quotes or browse to it.

“C:\Users\Administrator\Desktop\Backup PRTG.bat”

Next it will prompt you to enter the Administrator password.

 

Possible Errors

C:\Users\Administrator\Desktop>”Backup PRTG.bat”
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc
Searching for host…
Connecting to host…
Authenticating…
Host key does not match configured key fingerprint “ssh-ed25519 255 abc”!
Host key fingerprint is ssh-ed25519 255 def.
Authentication failed.
Error

Getting key exchange to work can be a challenge. The key is to use the WinSCP program to try and connect.

(1) Generate a key

(2) Use the connection dialog and then advanced to specify the key

(3) Once you have a successful connection, use the facility to copy/paste the fingerprint.

Tags

Share this article

Leave a Reply

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

Scroll to Top