logRotate
Definição
logRotate
The
logRotate
command is an administrative command that allows you to rotate the MongoDB server log and/or audit log to prevent a single logfile from consuming too much disk space.You must issue the
logRotate
command against the banco de dados admin.
Compatibilidade
Esse comando está disponível em implantações hospedadas nos seguintes ambientes:
MongoDB Atlas: o serviço totalmente gerenciado para implantações do MongoDB na nuvem
Importante
Esse comando não é suportado nos clusters M,0 M, M,2 5M10+ e Flex. Para obter mais informações, consulte Comandos não suportados.
MongoDB Enterprise: a versão autogerenciada e baseada em assinatura do MongoDB
MongoDB Community: uma versão com código disponível, de uso gratuito e autogerenciada do MongoDB
Sintaxe
O comando tem a seguinte sintaxe:
db.adminCommand( { logRotate: <integer or string>, comment: <string> } )
Campos de comando
O comando utiliza os seguintes campos:
Campo | Tipo | Descrição |
---|---|---|
| inteiro ou string | The log or logs to rotate, according to the following:
|
| string | Opcional. A message logged by the server to the log file and audit file at time of log rotation. |
You may also rotate the logs by sending a SIGUSR1
signal to the
mongod
process.
For example, if a running mongod
instance has a
process ID (PID) of 2200
, the following command rotates the log
file for that instance on Linux:
kill -SIGUSR1 2200
Limitações
Your
mongod
instance needs to be running with the--logpath [file]
option in order to uselogRotate
Auditoria must be enabled to rotate the audit log.
Comportamento
The systemLog.logRotate
setting or
--logRotate
option specify
logRotate
's behavior.
When systemLog.logRotate
or --logRotate
are set to rename
, logRotate
renames the existing log file by appending the current timestamp to the
filename. The appended timestamp has the following form:
<YYYY>-<mm>-<DD>T<HH>-<MM>-<SS>
Then logRotate
creates a new log file with the same
name as originally specified by the systemLog.path
setting to
mongod
or mongos
.
When systemLog.logRotate
or --logRotate
are set to reopen
, logRotate
follows the typical Linux/Unix behavior, and simply closes the log file
then reopens a log file with the same name. With reopen
,
mongod
expects that another process renames the file
prior to the rotation, and that the reopen results in the creation of a
new file.
Exemplos
The following example rotates both the server log and the audit log:
db.adminCommand( { logRotate: 1 } )
The following example rotates only the audit log, and provides a custom message to the log file at time of rotation:
db.adminCommand( { logRotate: "audit", comment: "Rotating audit log" } )