Applicable to:
- Plesk for Linux
- Plesk for Windows
Question
How to change log rotation settings in Plesk for all domains at once?
Answer
It can be performed using Plesk command line utility or Plesk API-XML request:
Connect to the server via SSH and use the following command change log rotation setting for all domains:
# plesk bin domain -l| while read dom_name; do plesk bin domain -u $dom_name -log-bytime weekly; done
This command is switching log rotation condition to By time
and sets log rotation period as 1 week
.
To disable sending email about rotated log for all domains at once:
- Create list of all domains on the server:
# plesk bin site --list > /root/domains.txt
- Run the command to disable sending notifications:
# cat /root/domains.txt | while read i; do plesk bin site -u $i -log-email ""; done
Get an additional information about the plesk bin domain
utility options by the following command:
# plesk bin domain --help
Also, it is possible to use CLI commands to update rotation settings on a service plan level, or on a domain/subscription level. For example, to enable log rotation on the domain example.com once the current log file reaches the 200 KB size (by-size rotation), use the following command:
# plesk bin subscription -u example.com -log-bysize 200K
To enable weekly log rotation (by-time rotation) on the domain example.com:
# plesk bin subscription -u example.com -log-bytime weekly
To enable log rotation once the current log file reaches the 20 KB size on websites created by users of the plan Plan 1:
# plesk bin service_plan -u "Plan 1" -log_bysize 20K
To set weekly log rotation for subscriptions created by the plan Plan 1:
# plesk bin service_plan -u "Plan 1" -log-bytime weekly
Visit Reference for Command-Line Utilities for Linux guide for additional details about 'plesk bin service_plan -u' and 'plesk bin subscription -u' commands options.
Connect to the server via RDP and use the attached file in order to change log rotation setting for all or several websites.
Unzip the .bat
file, run it as Administrator and follow the instructions inside.
Modify log rotation settings using Plesk API request.
Send the API request to Plesk website. In the following example, XML API request changes log rotation setting for all domains of admin
account
CONFIG_TEXT: <packet version="1.6.3.0">
<log-rotation>
<set>
<filter>
<owner-id>1</owner-id>
</filter>
<settings>
<log-condition>
<log-bytime>Weekly</log-bytime>
</log-condition>
</settings>
</set>
</log-rotation>
</packet>
This API request switch log rotation condition to By time
and sets log rotation period as 1 week
.
The command line utility usage in Plesk Multi Server is different from standalone Plesk. Therefore, there's no way to use the command line utilities as on the standalone server. To update Log Rotation settings, use GUI instead.
Alternatively, use API requests from the command line to manage the domains:
-
Connect to the management node via SSH
-
Download the script attached and unpack it.
-
Open the script for editing in any text file and define values:
CONFIG_TEXT: snhost=""
user="admin"
password=""Specify service node IP address and admin's password in snhost and password parameters.
Also define log rotation settings. In the script there is an example of:
CONFIG_TEXT: <log-bysize>2097152</log-bysize>
<log-max-num-files>10</log-max-num-files>
<log-compress>true</log-compress>It will set log rotation by size in bytes, will keep maximum 10 log files and will compress logs.
The script will connect to the required service node (the one that will be specified in snhost), take the list of all domains and generate the API requests to enable and configure the rotation according to settings defined in <log-bysize>, <log-max-num-files> and <log-compress>.
-
Use the script:
# sh ./api-request.sh
Comments
11 comments
the windows log.zip does not work on Onyx 17.8
a quick fix
Replace the 3 top lines:
@echo off
set /p password="Please enter your Plesk administrator password: "
"%plesk_dir%\MySQL\bin\mysql.exe" -uadmin -p%password% -P8306 psa -s -r -e "select name from domains" > domains.txt
with these 2 lines:
@echo off
plesk db -s -r -e "select name from domains" > domains.txt
@Christopher
I verified the fix and added the updated script to the article. Thank you for your input.
Both the links to download (for Plesk 12.5 and older or for Plesk Onyx and newer) are wrong.
Hello @Gianluca!
Thank you for noticing, links were fixed.
I'm confused.
March 26, 2018 Christopher Danks reports that the windows log.zip has an issue.
Same Date Denis Bykov confirms above and updated the article
Today October 15, 2021 I downloaded log.zip and examined the log.bat file. It contains what was first recorded, and the file is dated 10/20/2016.
I'm new enough to this environment that I'm afraid of making a mistake. Can someone confirm why the above reported change was not applied to the bat file?
@Vladimir Chernikov
New question please. The Windows file originally included the following commands which deals with updating the log rotation either by time or by size:
"%plesk_cli%\domain.exe" -u %%a -log-bytime %value%
"%plesk_cli%\domain.exe" -u %%a -log-bysize %size%
What it did not do was to set the variable which influences how many files are to be retained.
I went ahead and added this line to force the maximum files to be retained to 25.
"%plesk_cli%\domain.exe" -u %%a -log-max-num-files 25
But there's still one more bit. The script also does not support log compression. I am looking at this page:
https://docs.plesk.com/en-US/obsidian/cli-win/using-command-line-utilities.43564/
What I find odd is that there is no reference to this domain.exe command. What I do find is a reference to site.exe:
https://docs.plesk.com/en-US/obsidian/cli-win/using-command-line-utilities/siteexe-sites.67068/
In the site.exe section I find a reference to "-log_compress"
Why is domain.exe not referenced, and dare I use "-log_compress" as a parameter to domain.exe?
Edit - I reported initially that the script failed on Win 2012. Appears that was my fault, I ran again with correct inputs and it's working fine.
Would really like to see docs for domain.exe
Latest update.
- Still hoping to find where domain.exe is declared in the docs.
- ran the script with -log_compress on a Windows 2016 server and it worked fine.
> For example, to enable log rotation on the domain example.com once the current log file reaches the 200 KB size (by-size rotation), use the following command:
> # plesk bin subscription -u example.com -log-bysize 200
This is wrong! Log-bysize is in MB.
Tested on Obsidian 18.0.39 Update #2.
Please sign in to leave a comment.