Automatic Updates for MaxMind GeoIP Databases

Linux specific questions/information are gathered here. The main thrust of topics are applied to Centos/RedHat(RH)/Debian/Ubuntu/Gentoo distributives

Automatic Updates for MaxMind GeoIP Databases

Postby lik » Sun Oct 16, 2011 3:01 pm

Automatic Updates for MaxMind GeoIP free Databases (GeoIP Legacy Databases):

1. Use official MaxMind GeoIP Update program. GeoIP updates require an active GeoIP subscription.
Can find more information at http://dev.maxmind.com/geoip/geoipupdate/

2. Manual download of free (*lite* in terms of MaxMind) databases:
geoipupdate.sh:
Code: Select all
#!/bin/sh

GEOIP_MIRROR="https://mailfud.org/geoip-legacy"
GEOIPDIR=/usr/share/GeoIP
TMPDIR=

DATABASES="GeoIP GeoIPv6 GeoIPCity GeoIPCityv6 GeoIPASNum GeoIPASNumv6 GeoIPISP GeoIPOrg"

if [ "${1}" = -f ] || [ "${1}" = --force ]; then
        force=true
fi

if [ -d "${GEOIPDIR}" ]; then
        cd $GEOIPDIR
        if [ -n "${DATABASES}" ]; then
                TMPDIR=$(mktemp -d geoipupdate.XXXXXXXXXX)

                echo "Updating GeoIP databases..."

                for db in $DATABASES; do
                        fname=$(basename $db)

                        if [ -f "${GEOIPDIR}/${fname}.dat" ] || [ ${force} ]; then
                                wget --no-verbose -t 3 -T 60 \
                                        --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0" \
                                        "${GEOIP_MIRROR}/${db}.dat.gz" \
                                        -O "${TMPDIR}/${fname}.dat.gz"
                                if [ $? -eq 0 ]; then
                                        gunzip -fdc "${TMPDIR}/${fname}.dat.gz" > "${TMPDIR}/${fname}.dat"
                                        mv "${TMPDIR}/${fname}.dat" "${GEOIPDIR}/${fname}.dat"
                                        chmod 0644 "${GEOIPDIR}/${fname}.dat"
                                        case ${fname} in
                                                GeoLite*) ln -sf ${fname}.dat `echo ${fname} | sed 's/GeoLite/GeoIP/'`.dat ;;
                                        esac
                                fi
                        fi
                done
                [ -d "${TMPDIR}" ] && rm -rf $TMPDIR
        fi
fi



MaxMind service database update frequency (FAQ):
The GeoIP2 and GeoIP Legacy Country and City and GeoIP Legacy Region databases are updated every Tuesday. All other databases are updated on the first Tuesday of the month.

Cron task can for regular updates might be:
Code: Select all
# GeoIP database update
20 3 * * 4 [ $(date +\%d) -le 7 ] && /usr/local/etc/scripts/geoipupdate.sh
lik
Founder
Founder
 
Posts: 497
Joined: Wed Dec 15, 2010 3:21 am

Return to Linux specific

 


  • Related topics
    Replies
    Views
    Last post
cron