SOLVED Iocage jail cold snapshot script - how to find the active pool?

bal0an

Explorer
Joined
Mar 2, 2012
Messages
72
Is there a way to print the currently active pool?
iocage activate sets a pool for iocage use.
How can I find out the active pool?

I'd like to automatically take a cold snapshot of <zpool>/iocage which requires knowledge about the currently active pool.

Code:
#!/bin/bash
echo $(date '+%Y-%m-%d %H:%M:%S') "Stopping all jails..."
iocage stop --rc
SNAPSHOT_NAME=$(date "+auto-%Y%m%d-%H%M")
echo $(date '+%Y-%m-%d %H:%M:%S') "Taking snapshot $SNAPSHOT_NAME"
zfs snapshot -r <zpool>/iocage@$SNAPSHOT_NAME
echo $(date '+%Y-%m-%d %H:%M:%S') "Starting all jails..."
iocage start --rc
echo $(date '+%Y-%m-%d %H:%M:%S') "Done."
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Well it's not elegant, but jls will give you an output that shows the path to the jail root(s), so you could grep it from there.

jls | grep -m 1 mnt | cut -f3 -d/
 

Alecmascot

Guru
Joined
Mar 18, 2014
Messages
1,177
iocage get -p
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
iocage get -p
Great! although that's not documented anywhere I could find.

I note that my option is faster by a second or two even though it's not as elegant/official.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Top