GeoLite2 database update script

Recently, I’ve been using Graylog for log management on my home network. Graylog is enterprise log management that is 100% open source. It collects logs from almost any device and allows you to visualize and search through the data.

Graylog offers the option to setup geolocation for IP addresses, which is really helpful. To map an IP to a physical location, Graylog needs an external database of IPs and locations. Currently, Graylog only supports MaxMind City databases in the MaxMind DB format. In this case, that’s either the GeoIP2 City database (paid) or the GeoLite2 City database (free, but not as accurate).

The catch is, this database updates once a month, and with that update, the directory name inside the GZIP file changes (e.g., May 2018 will be GeoLite2-City_20180501). Because of this, you’ll need a script to download the database, then unzip it and rename the directory to the path you’ve given to Graylog.

The script is over at GitHub, but also pasted below (check GitHub first).