..
- Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
+ Copyright (C) 2019-2020 Internet Systems Consortium, Inc. ("ISC")
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
**db-upgrade**
Conducts a database schema upgrade. This is useful when upgrading Kea.
- **db-dump**
+ **lease-dump**
Dumps the contents of the lease database (for MySQL, PostgreSQL,
or CQL backends) to a CSV (comma-separated values) text file.
The first line of the file contains the column names. This is meant
to be used as a diagnostic tool, so it provides a portable,
human-readable form of the lease data.
+ **lease-recount**
+ Recounts leases for MySQL or PostgreSQL database.
+
``backend``
Specifies the backend type. Currently allowed backends are: memfile,
mysql, and pgsql.
#!/bin/sh
-# Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
echo "$version"
return $error
}
+
+recount4_query() {
+ # recount IPv4 leases from scratch
+ query="
+START TRANSACTION;
+DELETE FROM lease4_stat;
+INSERT INTO lease4_stat (subnet_id, state, leases)
+ SELECT subnet_id, state, COUNT(*)
+ FROM lease4 WHERE state = 0 OR state = 1
+ GROUP BY subnet_id, state;
+COMMIT;
+"
+ return $query
+}
+
+recount6_query() {
+ # recount IPv6 leases from scratch
+ query="
+START TRANSACTION;
+DELETE FROM lease6_stat;
+INSERT INTO lease6_stat (subnet_id, lease_type, state, leases)
+ SELECT subnet_id, lease_type, state, COUNT(*)
+ FROM lease6 WHERE state = 0 OR state = 1
+ GROUP BY subnet_id, lease_type, state;
+COMMIT;
+"
+ return $query
+}
#!/bin/sh
-# Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# - database version check
# - database version upgrade
# - lease database dump
+# - lease database recount
# Get the location of the kea-admin scripts
printf " - for checking databaseB version when preparing for an upgrade.\n"
printf " - db-upgrade: Upgrades your database scheme\n"
printf " - lease-dump: Dump current leases to a CSV file\n"
+ printf " - lease-recount: Recount leases.
printf "\n"
printf "BACKEND - one of the supported backends: memfile|mysql|pgsql|cql\n"
printf "\n"
exit 0
}
+### Functions used for recount
+mysql_recount() {
+
+ printf "Recount leases from database\n"
+ QUERY4=recount4_query()
+ RESULT=$(mysql_execute "$QUERY")
+ ERRCODE=$?
+ if [ $ERRCODE -ne 0 ]
+ then
+ log_error "mysql failed to recount IPv4 leases, mysql status = $ERRCODE"
+ exit 1
+ fi
+
+ QUERY6=recount6_query()
+ RESULT=$(mysql_execute "$QUERY")
+ ERRCODE=$?
+ if [ $ERRCODE -ne 0 ]
+ then
+ log_error "mysql failed to recount IPv6 leases, mysql status = $ERRCODE"
+ exit 1
+ fi
+}
+
+pgsql_recount() {
+
+ printf "Recount leases from database\n"
+ QUERY4=recount4_query()
+ RESULT=$(pgsql_execute "$QUERY")
+ ERRCODE=$?
+ if [ $ERRCODE -ne 0 ]
+ then
+ log_error "pgsql failed to recount IPv4 leases, pgsql status = $ERRCODE"
+ exit 1
+ fi
+
+ QUERY6=recount6_query()
+ RESULT=$(pgsql_execute "$QUERY")
+ ERRCODE=$?
+ if [ $ERRCODE -ne 0 ]
+ then
+ log_error "pgsql failed to recount IPv6 leases, pgsql status = $ERRCODE"
+ exit 1
+ fi
+}
+
### Script starts here ###
# First, find what the command is
exit 0
fi
-is_in_list "${command}" "db-init db-version db-upgrade lease-dump"
+is_in_list "${command}" "db-init db-version db-upgrade lease-dump lease-recount"
if [ ${_inlist} -eq 0 ]; then
log_error "invalid command: ${command}"
usage
;;
esac
;;
+ lease-recount)
+ case ${backend} in
+ memfile)
+ log_info "memfile does not count leases"
+ ;;
+ mysql)
+ mysql_recount
+ ;;
+ pgsql)
+ pgsql_recount
+ ;;
+ cql)
+ log_info "cql does not count leases"
+ ;;
+ esac
+ ;;
esac
exit 0
Kea
kea-admin
Shell script for managing Kea databases
-2014-2018
+2014-2020
Internet Systems Consortium, Inc. ("ISC")
kea-admin
command
meant to be used as a diagnostic tool, so it provides a portable,
human-readable form of the lease data.
+ lease-recount
+ Recounts leases for MySQL or PostgreSQL database.
+
``backend``
Specifies backend type. Currently allowed backends are: memfile,
mysql and pgsql.