How to include details from Duplicacy
Let’s assume again your Duplicacy repository is at X:\YourRepositoryFolder and CLI files at “C:\Program Files\Duplicacy”
If we add the –stats option to Duplicacy backup, it will show some info about the backup.
If we add the –log global option, time and date will be added to the lines.
Typical result from a backup:
2019-06-17 01:24:14.700 INFO BACKUP_STATS Files: 23879 total, 40,574M bytes; 1 new, 42K bytes
2019-06-17 01:24:14.700 INFO BACKUP_STATS File chunks: 8259 total, 40,614M bytes; 1 new, 42K bytes, 31K bytes uploaded
2019-06-17 01:24:14.700 INFO BACKUP_STATS Metadata chunks: 5 total, 7,793K bytes; 3 new, 2,163K bytes, 975K bytes uploaded
2019-06-17 01:24:14.700 INFO BACKUP_STATS All chunks: 8264 total, 40,622M bytes; 4 new, 2,206K bytes, 1007K bytes uploaded
2019-06-17 01:24:14.700 INFO BACKUP_STATS Total running time: 00:00:24
Now we can pipe the log to a file,
extract some useful information into a variable, and then
- Store some in a local history log
- Send detail to Healthchecks along with the signal
Sample batch file:
REM Modify locations to your preference:
Set Log="%Temp%\Backuplog.txt"
Set Tempfile="%Temp%\TempStats.txt"
Set History="%Temp%\Backuplog_History.txt"
CD /D X:\YourRepositoryFolder
"C:\Program Files\Duplicacy\duplicacy.exe" -log backup -stats > %Log%
If Errorlevel 1 goto FAILED
REM (We get here if backup was successful)
REM One of the lines from the log (including –stats) might look like this:
REM 2019-05-17 23:53:10.418 INFO BACKUP_STATS Files: 23829 total, 40,534M bytes; 1 new, 45K bytes
REM (We don’t need the first 42 characters)
type %Log% | find "INFO BACKUP_STATS Files" > %Tempfile%
REM (Optional) Add to a history log:
type %Tempfile% >> %History%
REM Retrieve part of the line to send to the service (from character 42):
set /P Stats=<%Tempfile%
set Stats=%Stats:~42%
curl --user-agent "%Computername%" --data "%Stats%" https://hc-ping.com/your-check-url
REM This skips the rest of the script:
goto :EOF
:FAILED
REM (we could add some more info about why it failed)
curl --user-agent "%Computername%" --data "Backup failed – Exit code %errorlevel%" https://hc-ping.com/your-check-url/fail
Windows 10 before build 1803:
powershell.exe -command "&{Invoke-RestMethod https://hc-ping.com/your-check-url -headers @{'User-Agent'='%Computername%'} -body '%Stats%' -method POST}"
[Edit:Added code for] Windows 7 with User-Agent and POST data (UploadString)
powershell.exe -command "&{($Web=New-Object System.Net.WebClient).Headers.add('User-Agent','%Computername%');$Web.UploadString('https://hc-ping.com/your-check-url', "POST", '%Stats%')}"
Normally we don’t need to store much data in the log. here’s an example using only User-Agent:
[Edit:Added code for] Windows 7 using only User-Agent and GET (DownloadString)
powershell.exe -command "&{($Web=New-Object System.Net.WebClient).Headers.add('User-Agent','%Computername% %Stats%');$Web.DownloadString('https://hc-ping.com/your-check-url')}"
This Windows 7 samples also work for Windows 10
Please consider which details you want to send to the public server in case of data breach etc.!