-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# Simple script to delete partitions older than 30 days. Useful if TTL functionality is misbehaving or you've altered TTL manually after cearing partitions. | ||
|
||
DAYS_TO_KEEP=31 | ||
CLICKHOUSE_ADDRESS=localhost:8123 | ||
|
||
# get the earliest date of partitions from system tables | ||
EARLIEST_DATE=`curl -G ${CLICKHOUSE_ADDRESS} --data-urlencode "query=SELECT partition FROM system.parts WHERE table = 'DNS_LOG' ORDER BY partition LIMIT 1"` | ||
|
||
# latest acceptable date to delete partitions | ||
LATEST_DATE=`date +%Y%m%d -d "-${DAYS_TO_KEEP} days"` | ||
|
||
# calculate the number of days between the two | ||
let DIFF=($(date +%s -d ${LATEST_DATE})-$(date +%s -d ${EARLIEST_DATE}))/86400 | ||
DIFF=$(($DIFF+$DAYS_TO_KEEP)) | ||
|
||
for i in `seq $DIFF -1 $DAYS_TO_KEEP` | ||
do | ||
DATE=`date +%Y%m%d -d "-$i days"` | ||
echo "Deleting partition ${DATE}" | ||
curl -X POST -G -H "Transfer-Encoding: chunked" ${CLICKHOUSE_ADDRESS} --data-urlencode "query=ALTER TABLE DNS_LOG DROP PARTITION ${DATE}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters