forked from percona/pmm-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
purge-qan-data
executable file
·46 lines (37 loc) · 1.16 KB
/
purge-qan-data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# Logging to console and log file.
exec > >(tee -a /var/log/purge-qan-data.log)
exec 2>&1
if [ -z "$(pt-archiver --version)" ]; then
echo "pt-archiver is not in PATH" >&2
exit 1
fi
MYCNF="${MYCNF}"
DB="${DB:-pmm}"
INTERVAL="${QUERIES_RETENTION:-8}"
set -eu
ts() {
echo -n "$(date +'%Y-%m-%dT%T') "
echo "$*"
}
do_table() {
local tbl="$1"
local where="$2"
ts "Purging $tbl..."
pt-archiver \
--source "F=$MYCNF,D=$DB,t=$tbl" \
--purge \
--limit 1000 \
--no-check-charset \
--why-quit \
--statistics \
--commit-each \
--no-version-check \
--where "$where"
}
ts "Starting to purge $DB data older than $INTERVAL days."
do_table "agent_log" "FROM_UNIXTIME(sec) < NOW() - INTERVAL $INTERVAL DAY"
do_table "query_examples" "period < NOW() - INTERVAL $INTERVAL DAY"
do_table "query_global_metrics" "start_ts < NOW() - INTERVAL $INTERVAL DAY"
do_table "query_class_metrics" "start_ts < NOW() - INTERVAL $INTERVAL DAY"
ts "Done purging data."