Created
February 13, 2019 14:21
-
-
Save olivertappin/dcf861546991e38ca76528ed22d4ab47 to your computer and use it in GitHub Desktop.
Export all data from the Consul KV store into consul kv put commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$output = shell_exec('consul kv export'); | |
if (null === $output) { | |
echo 'Could not run `consul kv export`. Is consul installed?' . PHP_EOL; | |
exit(1); | |
} | |
$data = json_decode($output, true); | |
foreach ($data as $item) { | |
$value = base64_decode($item['value']); | |
// Skip items with empty values | |
if ('' === $value) { | |
// Optional output to remove these keys | |
// echo 'consul kv delete ' . $item['key'] . ' ' . $value . PHP_EOL; | |
continue; | |
} | |
// Quote values containing special characters | |
if ($value !== htmlspecialchars($value)) { | |
$value = '"' . $value . '"'; | |
} | |
echo 'consul kv put ' . $item['key'] . ' ' . $value . PHP_EOL; | |
} | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
issue: