SOLVED iocage import failed & how to use zfs send/receive

theomolenaar

Dabbler
Joined
Jun 12, 2016
Messages
43
Hello FreeNAS friends. I am trying to import a jail from a backup with iocage import [jailname]. But it fails to complete this command.
I have two files in my images folder: /mnt/pool1/iocage/images
mediajail_2020-11-12.sha256
mediajail_2020-11-12.zip

iocage import mediajail
Importing dataset: mediajail
Importing dataset: mediajail/root
cannot receive: failed to read from stream
zsh: killed iocage import mediajail


I unzipped mediajail_2020-11-12.zip and have two files here:
/mnt/pool1/iocage/images/unzipped/mnt/pool1/iocage/images
  • mediajail_2020-11-12
  • mediajail_2020-11-12_root
I have found this reddit post with a comment where they mention to manually create a dataset. And afterwards use zfs send and receive to "import" the backup data back into this dataset.
What I did was this. I created a jail:
iocage create -n mediajail -r 11.2-RELEASE ip4_addr="vnet0|xxx.xxx.xxx.xx/24" defaultrouter="xxx.xxx.xxx.x" boot="on" host_hostname="mediajail" vnet="on"
This jail is running successfully. But how exactly do I have to use zfs send and receive?
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Usually, you will want to use the root image to overwrite the one in the newly created jail, so it will look something like this:
zfs recv -F pool1/iocage/jails/mediajail/root < /mnt/pool1/iocage/images/unzipped/mnt/pool1/iocage/images/mediajail_2020-11-12_root

The jail needs to be stopped when you run that command and this is completely not tested/supported by me. (I have never tried to restore a jail like that... worst case you would need to scrap the jail and make a new one)

Generally speaking, you should never need to backup the root filesystem of a jail because everything important to you lives outside it in a mounted location in your pool, so recreating a jail with the same mounts should get you back the same jail functions with nothing lost.
 

theomolenaar

Dabbler
Joined
Jun 12, 2016
Messages
43
Okay solved it. The solution was in the linked reddit post. I discovered there was no need to create a jail with iocage create etc..
What you need to do after unzipping your jail backup is:
cd /mnt/pool1/iocage/images/unzipped/mnt/pool1/iocage/images zfs create pool1/iocage/jails/mediajail zfs recv -F pool1/iocage/jails/mediajail < mediajail_2020-11-12 zfs recv -F pool1/iocage/jails/mediajail/root < mediajail_2020-11-12_root
The last command will take a few minutes depending on the size of your jail.

After this I restarted Truenas just to make sure that Truenas sees this new jail. (Not sure if this step is necessary though).
Login to Truenas and go to Jails. Start the jail.
My restored jail wouldn't start initially. Had to remove a mount to a folder that didn't exist anymore.
 
Top