Skip to content

Commit

Permalink
ES/backup: fix issue with monthly/yearly copies.
Browse files Browse the repository at this point in the history
The condition "first week of the month" would be TRUE 7 days in a row,
meaning that the first day "monthly/$fname" is found missed, it will be
created -- and all the other days logrotate would produce error messages
like `ln: creating hard link ...: File exists`. It doesn't look really
good and makes me wonder: maybe some time monthly rotation might happen
*after* this "first week", and we would end up without monthly copy?

So now new copy is created next to the rotation of monthly/yearly
copies. And it seems to look better now.
  • Loading branch information
mgolosova committed Dec 13, 2019
1 parent c300510 commit 93b1ab4
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions Utils/Elasticsearch/tools/daily/es_backup.logrotate
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,14 @@ extension .tar.gz
rotate 4
prerotate
base_dir=%%DIR%%
# create dirs for monthly/yearly copies

# handle monthly/yearly copies
for d in monthly yearly; do
mkdir -p -m 0700 "${base_dir}/$d"
fname="${base_dir}/$d/`basename $1`"
[ -f "${fname}" ] || ln "$1" "$fname"
done

fname=`basename $1`

# copy rotated file:

# - to monthly backups every 1st week of the month
day=`date +%_d`
[ $day -ge 1 -a $day -le 7 ] && ln "$1" "${base_dir}/monthly/${fname}"

# - to yearly backups every 1st week of the year
day=`date +%_j`
[ $day -ge 1 -a $day -le 7 ] && ln "$1" "${base_dir}/yearly/${fname}"

# make sure we return "success"
true
endscript
Expand Down

0 comments on commit 93b1ab4

Please sign in to comment.