reset-learns.sh 1.6 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. read -r -p "Are you sure you want to reset learned hashes from Rspamd (fuzzy, bayes, neural)? [y/N] " response
  3. response=${response,,} # tolower
  4. if [[ "$response" =~ ^(yes|y)$ ]]; then
  5. echo "Working, please wait..."
  6. REDIS_ID=$(docker ps -qf name=redis-mailcow)
  7. RSPAMD_ID=$(docker ps -qf name=rspamd-mailcow)
  8. if [ -z ${REDIS_ID} ] || [ -z ${RSPAMD_ID} ]; then
  9. echo "Cannot determine Redis or Rspamd container ID"
  10. exit 1
  11. else
  12. echo "Stopping Rspamd container"
  13. docker stop ${RSPAMD_ID}
  14. echo "LUA will return nil when it succeeds or print a warning/error when it fails."
  15. echo "Deleting all RS* keys - if any"
  16. docker exec -it ${REDIS_ID} redis-cli EVAL "for _,k in ipairs(redis.call('keys', ARGV[1])) do redis.call('del', k) end" 0 'RS*'
  17. echo "Deleting all BAYES* keys - if any"
  18. docker exec -it ${REDIS_ID} redis-cli EVAL "for _,k in ipairs(redis.call('keys', ARGV[1])) do redis.call('del', k) end" 0 'BAYES*'
  19. echo "Deleting all learned* keys - if any"
  20. docker exec -it ${REDIS_ID} redis-cli EVAL "for _,k in ipairs(redis.call('keys', ARGV[1])) do redis.call('del', k) end" 0 'learned*'
  21. echo "Deleting all fuzzy* keys - if any"
  22. docker exec -it ${REDIS_ID} redis-cli EVAL "for _,k in ipairs(redis.call('keys', ARGV[1])) do redis.call('del', k) end" 0 'fuzzy*'
  23. echo "Deleting all tRFANN* keys - if any"
  24. docker exec -it ${REDIS_ID} redis-cli EVAL "for _,k in ipairs(redis.call('keys', ARGV[1])) do redis.call('del', k) end" 0 'tRFANN*'
  25. echo "Starting Rspamd container"
  26. docker start ${RSPAMD_ID}
  27. fi
  28. fi