mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 15:35:17 +00:00
Revert "[#2038] kea-admin lease-export mysql"
This reverts commit 3dc6b3e43f
.
This commit is contained in:
@@ -62,8 +62,7 @@ COMMAND: Currently supported operations are:
|
||||
- db-version: Checks version of the existing database schema. Useful
|
||||
- for checking database version when preparing for an upgrade.
|
||||
- db-upgrade: Upgrades your database schema.
|
||||
- lease-dump: Dumps current leases to a human-readable CSV file.
|
||||
- lease-export: Dumps current leases to a memfile-ready CSV file.
|
||||
- lease-dump: Dumps current leases to a CSV file.
|
||||
- stats-recount: Recounts lease statistics.
|
||||
|
||||
BACKEND - one of the supported backends: memfile|mysql|pgsql|cql
|
||||
@@ -80,7 +79,7 @@ PARAMETERS: Parameters are optional in general, but may be required
|
||||
-d or --directory - path to upgrade scripts (default: %s)
|
||||
-v or --version - print kea-admin version and quit.
|
||||
|
||||
Parameters specific to lease-dump, lease-export:
|
||||
Parameters specific to lease-dump:
|
||||
-4 to dump IPv4 leases to file
|
||||
-6 to dump IPv6 leases to file
|
||||
-o or --output - name of file to which leases will be dumped
|
||||
@@ -633,38 +632,6 @@ cql_dump() {
|
||||
exit 0
|
||||
}
|
||||
|
||||
mysql_export() {
|
||||
# Check the lease type was specified.
|
||||
if test "${dump_type}" != '4' && test "${dump_type}" != '6'; then
|
||||
log_error "lease-export: lease type ( -4 or -6 ) needs to be specified"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check that an output file was specified.
|
||||
if test -z "${dump_file}"; then
|
||||
log_error "you must specify an output file for lease-export"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If output file exists, notify user, give them a chance to bail.
|
||||
check_file_overwrite "${dump_file}"
|
||||
|
||||
# Run the SQL query.
|
||||
sql_query="
|
||||
CALL lease${dump_type}DumpHeader;
|
||||
CALL lease${dump_type}ExportData;
|
||||
"
|
||||
output="$(mysql_execute "${sql_query}")"
|
||||
|
||||
# Translate tabs to commas and write to file.
|
||||
printf '%s\n' "${output}" | tr '\t' ',' > "${dump_file}"
|
||||
|
||||
# Print a confirmation message.
|
||||
printf 'lease%s successfully exported to %s.\n' "${dump_type}" "${dump_file}"
|
||||
}
|
||||
|
||||
### Functions used for recounting statistics
|
||||
mysql_recount() {
|
||||
printf "Recount lease statistics from database\n"
|
||||
@@ -722,7 +689,7 @@ if test "${command}" = "-v" || test "${command}" = "--version" ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
is_in_list "${command}" "db-init db-version db-upgrade lease-dump lease-export stats-recount"
|
||||
is_in_list "${command}" "db-init db-version db-upgrade lease-dump stats-recount"
|
||||
if [ "${_inlist}" -eq 0 ]; then
|
||||
log_error "invalid command: ${command}"
|
||||
usage
|
||||
@@ -928,22 +895,6 @@ case ${command} in
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
lease-export)
|
||||
case ${backend} in
|
||||
memfile)
|
||||
log_error 'exporting from memfile to memfile'
|
||||
;;
|
||||
mysql)
|
||||
mysql_export
|
||||
;;
|
||||
pgsql)
|
||||
pgsql_export
|
||||
;;
|
||||
cql)
|
||||
log_error 'lease-export cql is deprecated'
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
stats-recount)
|
||||
case ${backend} in
|
||||
memfile)
|
||||
|
@@ -52,7 +52,7 @@ const int MLM_MYSQL_FETCH_FAILURE = 0;
|
||||
|
||||
/// @name Current database schema version values.
|
||||
//@{
|
||||
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 13;
|
||||
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 12;
|
||||
const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 0;
|
||||
|
||||
//@}
|
||||
|
@@ -303,7 +303,7 @@ ALTER TABLE lease6
|
||||
ADD CONSTRAINT fk_lease6_hwaddr_source FOREIGN KEY (hwaddr_source)
|
||||
REFERENCES lease_hwaddr_source (hwaddr_source);
|
||||
|
||||
# Procedure that returns a result set containing the column names for lease4 dumps
|
||||
# FUNCTION that returns a result set containing the column names for lease4 dumps
|
||||
DROP PROCEDURE IF EXISTS lease4DumpHeader;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease4DumpHeader()
|
||||
@@ -312,7 +312,7 @@ SELECT 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_r
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Procedure that returns a result set containing the data for lease4 dumps
|
||||
# FUNCTION that returns a result set containing the data for lease4 dumps
|
||||
DROP PROCEDURE IF EXISTS lease4DumpData;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease4DumpData()
|
||||
@@ -335,7 +335,7 @@ ORDER BY l.address;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Procedure that returns a result set containing the column names for lease6 dumps
|
||||
# FUNCTION that returns a result set containing the column names for lease6 dumps
|
||||
DROP PROCEDURE IF EXISTS lease6DumpHeader;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease6DumpHeader()
|
||||
@@ -344,7 +344,7 @@ SELECT 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,ia
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Procedure that returns a result set containing the data for lease6 dumps
|
||||
# FUNCTION that returns a result set containing the data for lease6 dumps
|
||||
DROP PROCEDURE IF EXISTS lease6DumpData;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease6DumpData()
|
||||
@@ -691,7 +691,7 @@ SELECT 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_r
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Procedure that returns a result set containing the data for lease4 dumps
|
||||
# FUNCTION that returns a result set containing the data for lease4 dumps
|
||||
DROP PROCEDURE IF EXISTS lease4DumpData;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease4DumpData()
|
||||
@@ -723,7 +723,7 @@ SELECT 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,ia
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Procedure that returns a result set containing the data for lease6 dumps
|
||||
# FUNCTION that returns a result set containing the data for lease6 dumps
|
||||
DROP PROCEDURE IF EXISTS lease6DumpData;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease6DumpData()
|
||||
@@ -4076,138 +4076,6 @@ ALTER TABLE dhcp6_options
|
||||
UPDATE schema_version
|
||||
SET version = '12', minor = '0';
|
||||
|
||||
DROP FUNCTION IF EXISTS colonSeparatedHex;
|
||||
DELIMITER $$
|
||||
CREATE FUNCTION colonSeparatedHex(hex VARCHAR(64))
|
||||
RETURNS VARCHAR(64)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
DECLARE i INT;
|
||||
DECLARE length INT;
|
||||
DECLARE output VARCHAR(64);
|
||||
SET i = 3;
|
||||
SET length = LENGTH(hex);
|
||||
SET output = SUBSTR(hex, 1, 2);
|
||||
label: WHILE i < length DO
|
||||
SET output = CONCAT(output, ':', SUBSTR(hex, i, 2));
|
||||
SET i = i + 2;
|
||||
END WHILE label;
|
||||
SET output = LOWER(output);
|
||||
RETURN output;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Modify the procedure to call colonSeparatedHex() on MAC addresses.
|
||||
DROP PROCEDURE IF EXISTS lease4DumpData;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease4DumpData()
|
||||
BEGIN
|
||||
SELECT
|
||||
INET_NTOA(l.address),
|
||||
IFNULL(colonSeparatedHex(HEX(l.hwaddr)), ''),
|
||||
IFNULL(colonSeparatedHex(HEX(l.client_id)), ''),
|
||||
l.valid_lifetime,
|
||||
l.expire,
|
||||
l.subnet_id,
|
||||
l.fqdn_fwd,
|
||||
l.fqdn_rev,
|
||||
l.hostname,
|
||||
s.name,
|
||||
IFNULL(l.user_context, '')
|
||||
FROM
|
||||
lease4 l
|
||||
LEFT OUTER JOIN lease_state s on (l.state = s.state)
|
||||
ORDER BY l.address;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Procedure used in lease-export to output a memfile-ready CSV file
|
||||
DROP PROCEDURE IF EXISTS lease4ExportData;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease4ExportData()
|
||||
BEGIN
|
||||
SELECT
|
||||
INET_NTOA(l.address),
|
||||
IFNULL(colonSeparatedHex(HEX(l.hwaddr)), ''),
|
||||
IFNULL(colonSeparatedHex(HEX(l.client_id)), ''),
|
||||
l.valid_lifetime,
|
||||
UNIX_TIMESTAMP(l.expire),
|
||||
l.subnet_id,
|
||||
l.fqdn_fwd,
|
||||
l.fqdn_rev,
|
||||
l.hostname,
|
||||
l.state,
|
||||
IFNULL(l.user_context, '')
|
||||
FROM
|
||||
lease4 l
|
||||
ORDER BY l.address;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Modify the procedure to call colonSeparatedHex() on MAC addresses.
|
||||
DROP PROCEDURE IF EXISTS lease6DumpData;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease6DumpData()
|
||||
BEGIN
|
||||
SELECT
|
||||
l.address,
|
||||
IFNULL(colonSeparatedHex(HEX(l.duid)), ''),
|
||||
l.valid_lifetime,
|
||||
l.expire,
|
||||
l.subnet_id,
|
||||
l.pref_lifetime,
|
||||
IFNULL(t.name, ''),
|
||||
l.iaid,
|
||||
l.prefix_len,
|
||||
l.fqdn_fwd,
|
||||
l.fqdn_rev,
|
||||
l.hostname,
|
||||
IFNULL(colonSeparatedHex(HEX(l.hwaddr)), ''),
|
||||
IFNULL(l.hwtype, ''),
|
||||
IFNULL(h.name, ''),
|
||||
IFNULL(s.name, ''),
|
||||
IFNULL(l.user_context, '')
|
||||
FROM lease6 l
|
||||
left outer join lease6_types t on (l.lease_type = t.lease_type)
|
||||
left outer join lease_state s on (l.state = s.state)
|
||||
left outer join lease_hwaddr_source h on (l.hwaddr_source = h.hwaddr_source)
|
||||
ORDER BY l.address;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Procedure used in lease-export to output a memfile-ready CSV file
|
||||
DROP PROCEDURE IF EXISTS lease6ExportData;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease6ExportData()
|
||||
BEGIN
|
||||
SELECT
|
||||
l.address,
|
||||
IFNULL(colonSeparatedHex(HEX(l.duid)), ''),
|
||||
l.valid_lifetime,
|
||||
UNIX_TIMESTAMP(l.expire),
|
||||
l.subnet_id,
|
||||
l.pref_lifetime,
|
||||
l.lease_type,
|
||||
l.iaid,
|
||||
l.prefix_len,
|
||||
l.fqdn_fwd,
|
||||
l.fqdn_rev,
|
||||
l.hostname,
|
||||
IFNULL(colonSeparatedHex(HEX(l.hwaddr)), ''),
|
||||
IFNULL(l.hwtype, ''),
|
||||
IFNULL(h.name, ''),
|
||||
l.state,
|
||||
IFNULL(l.user_context, '')
|
||||
FROM lease6 l
|
||||
left outer join lease_hwaddr_source h on (l.hwaddr_source = h.hwaddr_source)
|
||||
ORDER BY l.address;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Update the schema version number
|
||||
UPDATE schema_version
|
||||
SET version = '13', minor = '0';
|
||||
|
||||
# This line concludes database upgrade to version 12.
|
||||
|
||||
# Notes:
|
||||
|
Reference in New Issue
Block a user