Description

This document helps in understanding how to archive the logs in Juniper excluding multiple file names or directory.

Symptoms

User was unable to use below command to archive var/logs and exclude multiple file/directory names.

labroot@lab_re0>file archive exclude {“*objmon*”,”*traces*”} source /var/log destination /var/tmp/TEST 

/var/tmp/TEST.tgz     

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

/bin/tar: *traces*: Cannot stat: No such file or directory

Solution

In order to archive multiple files, we can use below 2 methods:

1) via Linux:

lab_re0>start shell

lab_re0$ tar --exclude={"*trace*","*objmon*"} /var/log/* -zcvf /var/tmp/varlog.tgz

 

2) via Operational mode command: We need to specify the log location again in second file that we want to exclude from the logs collected.

file archive exclude {"*objmon*",--exclude=/var/log/"*trace*"} source /var/log/* destination /var/tmp/TEST compress


In above commands, any file or directory, with character 'objmon' or 'trace' in name will be excluded from the archival process.

 

PR1794532 enhanced the CLI operational mode command in Junos 25.3R1 and 25.3R1-EVO to support more than one folder/regex to exclude. (Eg, exclude traces, trace-logs, journal from /var/log) Users can exclude multiple folder/regex with below formats:

file archive exclude [traces trace-logs journal] source /var/log/ destination /var/tmp/varlog-archive.tgz
file archive exclude traces exclude trace-logs exclude journal source /var/log/ destination /var/tmp/varlog-archive.tgz

Modification History

2024-05-22 : Article Created

2025-06-12 : Solution is updated with PR1794532

Related Information

Refer KB for archival of logs in Evo: KB78298 [juniper.net]

 

Refer KB for archival of logs in Junos: KB20569 [juniper.net]