Question
The local laws of my country require storing all server logs for a long period. How do I set up storing of websites' logs for years in Plesk?
Important
- Plesk recommendsnot to disable log rotation and not to store log files for a long period, because it may cause overuse of the disk space and affect the server performance.
- Please note that when a website is removed, its logs are removed as well. To prevent that from happening, store required log files on a remote/external storage or a database. Third-party log management software or a bash script provided below can be used for this.
Answer
To set up a non-standard period of log storage, apply the following:
-
To keep sensitive data safe, disable the IP addresses anonymization in Plesk: Go to Tools & Settings > Server Settings, clear the Anonymize IP addresses during log rotation and collecting of web statistics checkbox and click OK:
-
Download and configure the actual version of archive-logs.sh script.
Note: the corresponding repository may be found here.
-
Set a scheduled task to run a script in a periodic manner.
-
Here's how the typical script setup steps look like:
# # make sure the script is executable
# chmod +x archive-logs.sh
# # check help
# ./archive-logs.sh --help
# # create a config from sample
# ./archive-logs.sh -s > config.sh
# # edit it to suite your environment and target storage
# # execute the script with the config to check everything works as expected
# ./archive-logs.sh -c config.sh -l debug
# # add the command to root cron with desired period: "/path/to/archive-logs.sh -c /path/to/config.sh"
# # note that "-c /path/to/config.sh" can be skipped if the file is in the same directory as the "archive-logs.sh" script
Find detailed instruction on how to use the archive-logs.sh script below.
Script
How it works
By default, this script collects all known logs of the server, Plesk, and websites. You can view the list of the collected logs right in the script and modify it in a configuration file if required.
To get a list of available options, run the script with the --help option:
# ./archive-logs.sh --help
Usage: archive-logs [OPTIONS]
Collect and transfer logs for long-term storage.
-c, --config CONFIG
Use this config…