Skip to content

Instantly share code, notes, and snippets.

@jovemfelix
Last active December 2, 2022 13:03
Show Gist options
  • Save jovemfelix/e56d777e1c95d82c2cfa5b28616fe01e to your computer and use it in GitHub Desktop.
Save jovemfelix/e56d777e1c95d82c2cfa5b28616fe01e to your computer and use it in GitHub Desktop.

Get Credentials

HOST

❯ REDIS_HOSTS=$(oc -n iib-3scale-apim extract secret/backend-redis --keys=REDIS_STORAGE_SENTINEL_HOSTS --to=-)
# REDIS_STORAGE_SENTINEL_HOSTSecho $REDIS_HOSTS
redis://redis-storage-01.hm.example.com.br:26379,redis://redis-storage-02.hm.example.com.br:26379,redis://redis-storage-03.hm.example.com.br:26379

❯ FIRST_HOST=$(echo $REDIS_HOSTS| awk -F, '{print $1}'|  awk -F// '{print $2}' | awk -F: '{print $1}')echo $FIRST_HOST
redis-storage-01.hm.example.com.br
❯ REDIS_URL=$(oc -n iib-3scale-apim extract secret/backend-redis --keys=REDIS_STORAGE_URL --to=-)
# REDIS_STORAGE_URLecho $REDIS_URL
redis://:COKZjBba@mymaster:6379
❯ REDIS_USER=$(echo $REDIS_URL| awk -Fredis:// '{print $2}' |  awk -F@ '{print $1}' |  awk -F: '{print $1}')
❯ REDIS_PASS=$(echo $REDIS_URL| awk -Fredis:// '{print $2}' |  awk -F@ '{print $1}' |  awk -F: '{print $2}')echo $REDIS_USERecho $REDIS_PASS
COKZjBba

output variables

cat <<EOF
---
redis-cli -h $FIRST_HOST --pass "$REDIS_PASS" --scan > redis-full-scan.txt
---
EOF

SCAN

❯ redis-cli -h $FIRST_HOST --pass "$REDIS_PASS" --scan > redis-full-scan.txt

# orexport REDISCLI_AUTH=$REDIS_PASS
❯ redis-cli -h $FIRST_HOST --scan > redis-full-scan.txt

# example to output the last 7 days, from now (now=2022/11/28)for i in {1..7} ; do gdate --date="$(date) -${i} day" "+%Y%m%d" ; done
20221128
20221127
20221126
20221125
20221124
20221123
20221122
# create a list with the last 7 days from now, like: YYYYMMDD|YYYYMMDD|YYYYMMDD|YYYYMMDD|
s=''; for i in {1..7} ; do s+=$(gdate --date="$(date) -${i} day" "+%Y%m%d");s+='|' ; done
# remove the last '|'
listWithoutLastPipe=${s%|*}

# create the files that are out of range from the last week
grep -v -E $listWithoutLastPipe redis-full-scan.txt > redis-full-files-to-be-deleted.txt

# get only the pattern of days
grep -Eo 'day:[[:digit:]]+' redis-days-to-be-deleted.txt

# delete the days that are not into the last week
while read day; do
    echo "$line"
done < redis-days-to-be-deleted.txt

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment