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 recommends you not 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 you remove a website, you remove its logs as well. To prevent that from happening, store required log files on a remote/external storage or a database. You can use third-party log management software or a bash script provided below.
Answer
To set up a non-standard period of log storage, do 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.
-
Configure 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