@anonymous-piwik-user opened this Issue on January 4th 2012

I saw in the comments of 1411 that the PowerShell script for archiving needed to be updated to match the latest archive.sh

The attached file does that as well as a few other improvements. Here is the summary of changes:

  • Added test for the existence of the INI file so that script will fail if the INI file location is bad (which typically happens after upgrade if your INI is in a different location than the default used in the script)
  • Added function that is used to call to PHP.exe so that exit codes from the exe are trapped and the script is halted with an error if PHP returns a non-zero error code.
    This was added because I have been experiencing issues where PHP.exe CLI will crash when running archive but it does so silently when the archive is in a scheduled task. This should now cause the scheduled task to fail if the PHP.exe fails. This does not cover errors that are returned from the Piwik API
  • Made the token a replacement tag in the command arguments so that the error text for failure does not contain the actual token value.
  • Changed Write-Host to Write-Output which is better form since output can be redirected but Write-Host cannot.
  • Changed errors to use Write-Error which is better PowerShell convention.
  • Added Write-Verbose statement for PHP command arguments so that full arguments beign sent to the command can be inspected for debugging.
  • Added segments archiving to match the archive.sh file
  • Added ability to turn on logging of the PowerShell script to a log file. Log files rotate and the number of rotating logs is based on the $NUM_LOGS_TO_KEEP varaible at the top of the script. To turn on transcript logging, set $LOGGING_ENABLED to $true. The one drawback to this right now is that it doesn't capture the output of the PHP.exe so you don't get to see if there were errors returned from Piwik API.

If someone could get this into the codebase so that it becomes part of the next release, it would be much appreciated.
Keywords: powershell, archive

@anonymous-piwik-user commented on January 4th 2012

Attachment: Upgraded archive.windows.ps1 file.

@anonymous-piwik-user commented on January 4th 2012

Sorry that I didn't format that list very well; I wasn't thinking about it being wiki syntax.

@anonymous-piwik-user commented on January 4th 2012

And one more comment. The command line parameters for powershell when calling it from a scheduled task should be: Noninteractive Noprofile File "C:\inetpub\wwwroot\piwik\misc\cron\archive.windows.ps1"

Remove the curly braces and the ampersand and use the -File parameter rather than the -Command parameter. It's simpler and it's easier to read / understand.

Please update the documentation to reflect this.

@mattab commented on January 8th 2012 Member

Thank you for your contribution!


  • Can you think of any potential problem or limitation in this script VS the previous one?
  • Is there a way to keep backward compatibility for previous windows users having set up the previous script. This would be very important criteria
  • Note: we will soon officially deprecate archive.sh and ps1 and will use a new archive.php script instead, see #2327
@mattab commented on February 8th 2012 Member

Volox did you see my last comment? your answer would be very appreciated (otherwise will mark as wont fix since we will now have #2327 )

@mattab commented on January 31st 2014 Member

In 916d8d6e91301f84792b67bb863f6316c4bc0261: Starting January 2014, this script is now deprecated. Please only use the standard archive.php script in your scheduled task setup. See documentation at: http://piwik.org/docs/setup-auto-archiving/ Refs #1959 #1411 #2848

This Issue was closed on January 31st 2014
Powered by GitHub Issue Mirror