mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-26 10:38:00 +01:00
27 lines
475 B
Bash
27 lines
475 B
Bash
|
#!/bin/bash
|
||
|
set -e
|
||
|
echo "Log rotate starting..."
|
||
|
|
||
|
#The logs n days before will be compressed.
|
||
|
n=14
|
||
|
path=/var/log/docker
|
||
|
|
||
|
list=""
|
||
|
n_days_before=$(($(date +%s) - 3600*24*$n))
|
||
|
for dir in $(ls $path | grep -v "tar.gz");
|
||
|
do
|
||
|
if [ $(date --date=$dir +%s) -lt $n_days_before ]
|
||
|
then
|
||
|
echo "$dir will be compressed"
|
||
|
list="$list $dir"
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
if [ -n "$list" ]
|
||
|
then
|
||
|
cd $path
|
||
|
tar --remove-files -zcvf $(date -d @$n_days_before +%F)-.tar.gz $list
|
||
|
fi
|
||
|
|
||
|
echo "Log rotate finished."
|