→ Applies to: SynetoOS 4.x
Step 1. Connect to SynetoOS appliance via SSH as admin
ssh admin@<your_ip_address_or_hostname>
Step 2 (optional). Change into Solaris shell (in case you're directed to an unsupported shell)
un sh
Step 3. Get root privileges
sudo su -
Step 4. Create a file
touch /var/storage/support/check_metadata
Step 5. Give permissions to the file
chmod +x /var/storage/support/check_metadata
Step 6. Open file with editor
vi /var/storage/support/check_metadata
Step 7. Copy and paste the code in the file
#!/usr/bin/env python3
import sys
import unicodedata
import subprocess
import json
try:
from colorama import Fore, Style
colors = True
except ModuleNotFoundError:
process = subprocess.Popen(['pip3', 'install', '--upgrade', 'colorama'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
if process.returncode != 0:
colors = False
checkmark = unicodedata.lookup('CHECK MARK')
crossmark = unicodedata.lookup('BALLOT X')
questionmark = unicodedata.lookup('QUESTION MARK')
def get_datasets():
command = ["zfs", "list", "-Ho", "name"]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
if process.returncode != 0:
print("Failed to get list of datasets: {}".format(stderr.decode().strip()))
return []
datasets = stdout.decode().strip().split("\n")
# print("Retrieved datasets: {}".format(datasets))
return datasets
def get_metadata(dataset):
command = ["zfs-meta", "get", dataset]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
if process.returncode != 0:
print("Failed to get metadata for {}: {}".format(dataset, stderr.decode().strip()))
return {}
try:
return json.loads(stdout.decode().strip())
except json.JSONDecodeError:
print("Failed to parse metadata for {}: not a valid JSON document".format(dataset))
return {}
def check_metadata(dataset):
metadata = get_metadata(dataset)
num_keys = len(metadata)
if num_keys == 0:
if colors:
print(Fore.RED + crossmark + " Metadata empty for {}".format(dataset) + Style.RESET_ALL)
else:
print("Metadata empty for {}".format(dataset))
elif num_keys <= 2:
if colors:
print(Fore.YELLOW + questionmark + " Metadata valid for {}: too few keys".format(dataset) + Style.RESET_ALL)
else:
print("Metadata valid for {}: too few keys ({num_keys})".format(dataset, num_keys))
else:
if colors:
print(Fore.GREEN + checkmark + " Metadata valid for {} ({} keys)".format(dataset, num_keys) + Style.RESET_ALL)
else:
print("Metadata valid for {} ({} keys)".format(dataset, num_keys))
def main():
ds_root = 'datastores/'
datasets = get_datasets()
for dataset in datasets:
if ds_root in dataset:
check_metadata(dataset)
if __name__ == "__main__":
main()
Step 8. Start the tool
./check_metadata
The following error may occur. If this happens, execute Step 9 (optional).
root@syneto-os3:/var/storage/support# ./check_metadata Traceback (most recent call last): File "/var/storage/support/./check_metadata", line 7, in <module> from colorama import Fore, Style ModuleNotFoundError: No module named 'colorama' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/var/storage/support/./check_metadata", line 10, in <module> process = subprocess.Popen(['pip3', 'install', '--upgrade',], stdout=subprocess.PIPE, stderr=subprocess.PIPE) File "/usr/lib/python3.9/subprocess.py", line 951, in init self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.9/subprocess.py", line 1821, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'pip3' root@syneto-os3:/var/storage/support# vim check_metadata root@syneto-os3:/var/storage/support# ./check_metadata Traceback (most recent call last): File "/var/storage/support/./check_metadata", line 7, in <module> from colorama import Fore, Style ModuleNotFoundError: No module named 'colorama' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/var/storage/support/./check_metadata", line 10, in <module> process = subprocess.Popen(['pip3', 'install', '--upgrade', 'colorama'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) File "/usr/lib/python3.9/subprocess.py", line 951, in init self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.9/subprocess.py", line 1821, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'pip3'
Step 9 (optional). Install this package
python3 -m pip install colorama
After installing the package, start the tool again
./check_metadata