- Plesk for Linux
How to recalculate AWStats web-statistics using domain logs for previous months?
Connect to a Plesk server via SSH.
Download and unpack the script:
# wget https://plesk.zendesk.com/hc/article_attachments/360001568074/rebuild_awstats.tar.gz
# tar -xzvf rebuild_awstats.tar.gz
For Ubuntu 14.04, a symbolic link should be created:
# ln -s /usr/lib/plesk-9.0/logresolvemerge /usr/share/doc/awstats/examples/logresolvemerge.pl
Run this command to show help message:
Usage: ./rebuild_awstats.sh [options] [<domains...>]
Process all domains. If this option is not specified, then list of
domains to process must be provided.
Remove contents of webstat/ and webstat-ssl/ directories before
rebuilding statistics pages (originals are saved with numeric
suffix). Statistics will be rebuilt from logs only, only for
period covered by log files. If this parameter is not used, then
statistics is recalculated beginning on the month on which log files
start (if log starts in the middle of the month, then statistics
for first half of the month will not be present.)
Rebuild web-statistics for a domain using the command:
# ./rebuild_awstats.sh example.com
How script works
For each specified domain (or all domains, if the -A option is used), the script will memorize the log file's start date.
Then, it will remove AWStats data files for the months covered by the log files and rebuild them with corresponding information.
Finally, the script will build static pages with statistics summary for each month covered by the log files.
If the -F option is used, all AWStats data will be removed and new files will be generated using only the information stored in the log files.
In order to merge web-statistics which was created from scratch with AWStats statistics from another directory, the corresponding .txt file and the directory should be copied from the
webstat directory. For example, statistics of a domain for December were created from scratch. In this case, the following files should be copied from
- A .txt file dated by December 2018:
- A directory dated by December 2018:
Note: It is important to copy a .txt file, otherwise new statistics (from scratch) might be erased.
For every processed domain, the script will report this message:
CONFIG_TEXT: === example.com
Saving: webstat* --> webstat*.3
Logs begin on Apr 18 2018
access_log* (new/old/corrupted): 9/0/0
access_ssl_log* (new/old/corrupted): 71/0/0
Rebuilding static pages: 2018-04 2018-05 2018-06 2018-07
Restoring from a backup
The message "Saving: webstat* --> webstat*.3 " in the output above shows that the original directories are saved with a numeric suffix (the suffix is increased if the destination directory already exists). This makes it possible to roll-back to old AWStats statistics if needed.
In case the script was launched to recalculate statistics from scratch (with -F flag), which removes old web-statistics that is not stored in log files, it is possible to restore it from the backup that was created by the script.
If the script fails with one of the following error messages, visit this KB article for troubleshooting:
CONFIG_TEXT: ./rebuild_awstats.sh: line 210: /usr/share/awstats/tools/logresolvemerge.pl: No such file or directory
ERROR: failed to merge access_log*. Skipping domain.
CONFIG_TEXT: ERROR /usr/share/awstats/wwwroot/cgi-bin/awstats.pl cannot be executed.
CONFIG_TEXT: ERROR /usr/lib/cgi-bin/awstats/awstats.pl cannot be executed