How to rotate catalina.out using cron job

Still need help?

The Atlassian Community is here for you.

Ask the community

Purpose

By default, catalina.out file does not rollover, and with time it grows large. This script will be executed by a cron job, to tarball catalina.out file and empty the large file.

Solution

  1. First, create the executable backup.sh file

    backup.sh
    #!/bin/bash
    #Backup catalina* in a folder /backups in user home
    SRCDIR="path/to/bamboo-installation-directory/logs"
    DESTDIR="/home/$USER/backups"
    DATE_WITH_TIME=`date "+%Y%m%d-%H%M%S"`
    FILE_NAME="Catalina-backup"
    BACKUP_FILE=$FILE_NAME$DATE_WITH_TIME
    TARGET="catalina.out"
    if [ ! -d "$DESTDIR" ]; then 
         mkdir $DESTDIR
    fi
    cd $SRCDIR && \
         tar -czvf $BACKUP_FILE.tar.gz catalina.out  && \
         mv $FILE_NAME* $DESTDIR  && \
         truncate --size=0  $TARGET >&2
    exit 0
  2. Ensure the file is executable

    chmod +x /path/to/backup.sh
  3. create a cron job to run the script

    0 0 * * 5 /path/to/backup.sh >/dev/null 2>&1





Last modified on Aug 22, 2019

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.