Skip to content

Example: Automatically loading IP2Location DB3 into Redis and notify via Slack

Alexey Zilber edited this page Aug 5, 2020 · 1 revision

Example

Loading the DB3 IP2Location data into Redis via cron job.

  1. Create a geoip2redis directory and redis directory:
mkdir -p ~/geoip/ip2location/work/

Remember to make a user specific for this process, that has access to redis.

Example download and load bash script:

#!/bin/bash

cd ~/geoip/ip2location

if [ -e ip2location-DB3.zip ]; then
  if [ -e ip2location-DB3.zip.old ]; then
   rm -f ip2location-DB3.zip.old
  fi
mv ip2location-DB3.zip ip2location-DB3.zip.old
fi

wget -O ip2location-DB3.zip 'https://www.ip2location.com/download?token=<your ip2location download token>&file=DB3'

unzip -o -d work/ ip2location-DB3.zip IP-COUNTRY-REGION-CITY.CSV

./geoip2redis -f ip2location -i 3 -r cpgeoip1 -p 6379 work/IP-COUNTRY-REGION-CITY.CSV

touch .lastran

echo "GeoIP2Redis ip2location DB3 Redis updated" |mail -s "Updated Ip2Location GEOIP DB3 data" <webhook token>@<your slack group>.slack.com

Add a cron job to run it every month.

Clone this wiki locally