Day 16 - How to Archive Jenkins Logs Using Tar, Zip, and Unzip

๐Ÿงฐ Step-by-Step: Backup Jenkins Logs


๐Ÿ“ Step 1: Navigate to Jenkins Log Directory

cd /var/log/
ls jenkins/

๐Ÿ—œ๏ธ Step 2: Create a Compressed Archive Using tar

tar -czvf jenkins_06122020.tar.gz jenkins

Options Explained:

  • -c: Create a new archive

  • -z: Compress using gzip

  • -v: Verbose output

  • -f: Specify output file name

โœ… Check archive:

file jenkins_06122020.tar.gz
ls -ltr

๐Ÿ“ฆ Step 3: Move Archive and Extract It

mv jenkins_06122020.tar.gz /tmp/
cd /tmp/
tar -xzvf jenkins_06122020.tar.gz

Extract to a different location:

tar -xzvf jenkins_06122020.tar.gz -C /opt/

๐ŸŽ Bonus: Use zip & unzip as an Alternative


๐Ÿ“ฅ Install zip/unzip

yum install zip unzip -y

๐Ÿ—œ๏ธ Create Zip Archive

zip -r jenkins_06122020.zip jenkins
mv jenkins_06122020.zip /opt/

๐Ÿ“‚ Extract Zip

cd /opt/
rm -rf jenkins     # Remove existing dir if needed
unzip jenkins_06122020.zip

๐Ÿ’ก What I Learned

โœ… How to archive and compress logs with tar
โœ… Use gzip compression with .tar.gz
โœ… Extract archives to custom paths using -C
โœ… Use zip/unzip for compatibility
โœ… Ideal for scheduled backups and automation


๐Ÿ› ๏ธ Real-World Use Case

  • Regular log archiving to save space

  • Moving logs to another server or S3 bucket

  • Debugging Jenkins issues from historical logs


๐Ÿ”ฎ Next Steps

On Day 17, I'll learn Debian Package Management & Network Utilities

0
Subscribe to my newsletter

Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaharyar Shakir
Shaharyar Shakir