Adding a new site to AWStats is quick but by default will only pick up access logs from the present time onwards (as previous logs have been rotated/archived away). This is a quick walkthrough of a process to bring in those archived logs, ensuring not to conflict with automated background processing.
Configuration File
AWStats uses a per-site configuration file in /etc/awstats/:
# /etc/awstats/awstats.pynotes.bjdean.id.au.conf
# Global configuration
Include "/etc/awstats/awstats.conf"
# Site-specific configuration
SiteDomain="pynotes.bjdean.id.au"
HostAliases="pynotes.bjdean.id.au localhost 127.0.0.1"
LogFile="/var/log/apache2/pynotes.bjdean.id.au-access_log"
DirData="/var/lib/awstats/pynotes.bjdean.id.au"
The configuration follows a simple pattern: include the global settings, then override site-specific values. AWStats expects to find config files named awstats.HOSTNAME.conf in /etc/awstats/.
Importing Historical Logs
The standard AWStats update process (typically run every 10 minutes via /etc/cron.d/awstats) only processes the log indicated by LogFile. To import archived logs:
1. Pause Automatic Updates
Prevent the cron job from running during the import - for example comment or move aside /etc/cron.d/awstats.
2. Extract Archived Logs
Extract and combine archived logs into a single import file - eg. /tmp/pynotes-import
# Create the import file outside /var/log/apache2 first
# (creating it in /var/log/apache2 will loop the extraction)
ls -tr /var/log/apache2/pynotes*access* | xargs zcat -f > /tmp/pynotes-import
3. Temporarily Point Config to Import File
Edit the site configuration to process the consolidated import file: LogFile="/tmp/pynotes-import
4. Run the import
Remember to run the www-data user (or whichever user has write-access to the awstats data):
sudo -u www-data /usr/share/awstats/tools/update.sh
Monitor progress by watching for temporary files in the data directory (during process data files have a tmp tagged filename):
watch find /var/lib/awstats/ -mtime -10 -exec ls -ltd {} +
5. Verify and Clean Up
After the import completes:
- Check stats are appearing in the awstats cgi-bin web view
- Clean up
- set
LogFileback to the current access log - delete the import log
- re-enable awstats cron jobs
- set
Wait for the next 10-minute window and confirm the stats continue updating correctly in the data directory and the the web interface.
For more information on AWStats configuration and log processing, see the AWStats documentation.