Script to activate and deactivate a Pool

I have a Pool that I would like to activate and deactivate with a script.
At a certain time a script puts the pool online.
At another time a second script takes the pool offline.

What commands should these scripts run?

The only necessary commands would be zpool export $POOLNAME to take it offline, and zpool import $POOLNAME to bring it online. But this sounds like a very unusual request–what are you hoping to accomplish with this?

Mine is a need for security; I don’t want it to always be visible to the system, but only when I need it.
Is there another way to do this?

The sudo zpool export Test-Pool command did not give errors, but in the dashboard and in Storage the pool is always visible; in Datasets however it is not seen.

With the zpool import Test-Pool command I got:

cannot mount ‘/Offline-Pool’: failed to create mountpoint: Read-only file system
Import was successful, but unable to mount some datasets%

Then just select it with the mouse and I get the error:

[ENOENT] Path /Offline-Pool not found

 Error: Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/middlewared/", line 198, in call_method
    result = await self.middleware.call_with_audit(message['method'], serviceobj, methodobj, params, self)
  File "/usr/lib/python3/dist-packages/middlewared/", line 1466, in call_with_audit
    result = await self._call(method, serviceobj, methodobj, params, app=app,
  File "/usr/lib/python3/dist-packages/middlewared/", line 1428, in _call
    return await self.run_in_executor(prepared_call.executor, methodobj, *prepared_call.args)
  File "/usr/lib/python3/dist-packages/middlewared/", line 1321, in run_in_executor
    return await loop.run_in_executor(pool, functools.partial(method, *args, **kwargs))
  File "/usr/lib/python3.11/concurrent/futures/", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3/dist-packages/middlewared/schema/", line 191, in nf
    return func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/middlewared/schema/", line 53, in nf
    res = f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/middlewared/plugins/", line 422, in stat
    raise CallError(f'Path {_path} not found', errno.ENOENT)
middlewared.service_exception.CallError: [ENOENT] Path /Test-Pool not found

Even restarting TrueNAS I still get this error.
It is fair to point out that I currently have no datasets created on this pool.

You need to mount the pool to the correct path. If you’re writing scripts for this it’s probably better to use our APIs.

I just have to deactivate and activate it (or anything else that takes it offline).
I don’t know how to use the API.

I saw that if I export the pool and then reboot, the pool is online again.
This might be enough; when I need it I reboot and then, when I no longer need it, take it offline again.
But it would be better to use a command with a script because I can’t know if when I reboot someone is using another pool.

By doing this I always cause problems.
In the end I had to restore the starting situation.
My need remains, but I’ll open a separate topic.
Thanks to everyone anyway.

See this post, you need to specify the path: