How to export/import pools from CLI in TrueNAS Core?

Tenou

Cadet
Joined
Jan 22, 2020
Messages
9
Evening ya'll,

how can one export/import a pool from CLI in TrueNAS Core?
I need to export/import some pools on a daily basis due to financial reasons (power's getting expensive over here) and would like to automate this - however, the process implemented in TrueNAS seems to be far more sophisticated than the simple "zpool export/import" that I'm used to.
What exactly is happening in the background there and how can I replicate it to be used in the CLI, if possible at all?

Thanks in advance,
Leo
 
Joined
Jan 7, 2015
Messages
1,155
zpool export POOLNAME
zpool import POOLNAME

Should be just about all there is. I think its recommended to use the GUI these days
 

HarryMuscle

Contributor
Joined
Nov 15, 2021
Messages
161
zpool export POOLNAME
zpool import POOLNAME

Should be just about all there is. I think its recommended to use the GUI these days
I don't believe that will cause it to show up in the GUI though. If you want to do exactly what the GUI does but just from the command line you can call the API for importing or exporting the disk. It's what the GUI does on the back end.

Thanks,
Harry
 
Joined
Jan 7, 2015
Messages
1,155
Right I misunderstood. Im not sure on that one.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
zpool import POOLNAME
The mountpoint will be messed up if you do this. Do at least:
Code:
zpool import -o altroot=/mnt POOLNAME


I don't know how to do it in a UI equivalent way. Probably using the API or midlct.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
with midclt or via curl you can call the API... the commands you'll need will be pool.import_find (and with the job output from that) pool.import_pool

You can find the API docs on your own server http://truenas.ip/api/docs/ or formatted a little differently with some more descriptive examples at: https://www.truenas.com/docs/api/rest.html

That would be the only way to programmatically add a pool to the GUI
 

Tenou

Cadet
Joined
Jan 22, 2020
Messages
9
The middleware was the correct hint, thanks!
I now managed to import a pool using the pool.import_find, pool.import_pool and basic core.get_jobs function, however I'm struggling with the export part.
"midclt call pool.export" requires an integer pool id, in the docs "1" is being used as example, however I can't figure out where to find the ids corresponding to my pools. Is there something I'm missing?
The fact that a plain "1" is being used in the docs makes me think that it's not the pools guid or anything, but a non-unique count for all pools present.

EDIT: Nevermind, I managed to find that ID as well using "midclt call pool.query". Thank you all very much!
 
Last edited:

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
I would appreciate some sharing of the final syntax you used as the API docs are woefully scant on concrete examples that actually work.
 

Tenou

Cadet
Joined
Jan 22, 2020
Messages
9
Absolutely! I was already planning on publishing my script on github and linking it here, in case others run into the same issues.
I'm currently refining it and writing a small amount of documentation to go with it. Should be done in the next couple of days!
 

Tenou

Cadet
Joined
Jan 22, 2020
Messages
9
Welp, took me only a month to copy & paste this onto github.
Here you go: https://github.com/ThisIsTenou/truenas-spindown-automation/blob/main/pool-manager.sh

Since it's pretty much very specifically written for my environment, I found it hard to document it well enough (also I'm a lazy pos, which might've been the bigger factor here). If you have any questions, feel free to file a github issue, I'll happily answer and explain.

CC @sretalla since you asked :)
 
Top