#!/bin/sh

set -e

LOG_DIR={{ log_dir }}
LOGROTATE_DIR={{ rotate_dir }}
PATTERN={{ pattern }}
COMPRESS={{ xz_binary }}
KEEP_DAYS={{ keep_days }}

# Move out ${PATTERN} files
find ${LOG_DIR} -maxdepth 1 -type f -name ${PATTERN} -exec mv {} ${LOGROTATE_DIR}/ \;

# Compress 
find ${LOGROTATE_DIR} -maxdepth 1 -type f -name ${PATTERN} -exec ${COMPRESS} -9 {} \;

# Retent old files
find ${LOGROTATE_DIR} -maxdepth 1 -type f -mtime +${KEEP_DAYS} -delete
