Auto-archiving under windows 2003

(olivy) #1


I have a windows 2003 server whith piwik 0.5.5.
so, the “HOWTO auto-archiving” is for Unix-Linux with crontab.
My question is, is it possible making auto-archiving under windows server?


(fearworksmedia) #2

Also looking for an answer… please, someone?

(Vonv) #3

Hi there.
I had this problem, so this is my solution in DOS/batch mode. And it works style_emoticons/<#EMO_DIR#>/rolleyes.gif

  1. Get sed for windows: CoreUtils for Windows
    You will need: sed.exe, libiconv2.dll, libintl3.dll, regex2.dll
    Put all in a sed directory near your future script.

  2. Create 3 files:

You get your YOURADMINPASSENCODED in the file config/config.ini.php after your piwik is installed, it’s the value of "password = "


@echo on
echo .
echo Avant de lancer ce script:
echo creez au meme endroit un fichier TOKEN_AUTH.cmd
echo contenu une unique ligne:
echo set TOKEN_AUTH=
echo sans retour a la ligne
echo .


set PHP_BIN=<i>YOURPATH</i>\php5.2.12\php.exe
set PIWIK_PATH=<i>YOURPATH</i>\piwik\index.php


%PHP_BIN% %PIWIK_PATH% -- "module=API&method=UsersManager.getTokenAuth&userLogin=%PIWIK_SUPERUSER%&md5Password=%PIWIK_SUPERUSER_MD5_PASSWORD%&format=php&serialize=0" > $out$.bat
copy TOKEN_AUTH.cmd + $out$.bat $tmp$.bat > nul
call $tmp$.bat
del $tmp$.bat
del $out$.bat

%PHP_BIN% %PIWIK_PATH% -- "module=API&method=SitesManager.getAllSitesId&token_auth=%TOKEN_AUTH%&format=csv&convertToUnicode=0" > $out$.bat
copy ID_SITES.cmd + $out$.bat $tmp$.bat > nul

sed\sed -i ":a;N;$!ba;s/\n/ /g" $tmp$.bat
sed\sed -i ":a;N;$!ba;s/\r//g" $tmp$.bat

call $tmp$.bat
del $tmp$.bat
del $out$.bat

del sed*.*

FOR %%i IN (%ID_SITES%) DO (
  %PHP_BIN% %PIWIK_PATH% -- "module=API&method=VisitsSummary.getVisits&idSite=%%i&period=day&date=last52&format=xml&token_auth=%TOKEN_AUTH%"
  %PHP_BIN% %PIWIK_PATH% -- "module=API&method=VisitsSummary.getVisits&idSite=%%i&period=week&date=last52&format=xml&token_auth=%TOKEN_AUTH%"
  %PHP_BIN% %PIWIK_PATH% -- "module=API&method=VisitsSummary.getVisits&idSite=%%i&period=year&date=last52&format=xml&token_auth=%TOKEN_AUTH%"





Feel free to ask questions.

Improvement: use sed to get admin login and pass.

(fearworksmedia) #4


Thanks for this - I’m going to give it a try later!

The only thing that confused me was the URL you gave - I think it should be sed for Windows

I’ll let you know if it works for me!


(fearworksmedia) #5

Hello again,

It seems to work great! I will be trying it out over the next few days to see if the stats are updated correctly - I’ve set the batch file to be run at midnight in a task scheduling program (don’t like Windows Task Scheduler - I use JIT Scheduler, found at Gibin Software House).

Thanks again for sharing this solution - I think the Piwik people should cover this solution in their documentation because I’ve been looking for ages for this!

(Fabian Becker) #6

I’ve added a PowerShell script that does not require you to install anything (aside from PowerShell if you don’t have it…). Have a look at Archiving script: Port to Powershell · Issue #1411 · matomo-org/matomo · GitHub

(Vonv) #7

You’re right for the correct URL, my link was leading to the main utils, but as a Unix fan working on Windows, i adopted the fulll package, sed, hawk, tee,… style_emoticons/<#EMO_DIR#>/rolleyes.gif

Thanx a lot for JIT, i’ll try it.

For the Powershell: great but it needs to be installed and in my case, i adopted a solution as portable as possible.