import/export ZPOOL via bash script as non-root

banane

Cadet
Joined
Jan 3, 2022
Messages
3
Hello dear forum,

Initial situation / requirements :

I would like to create a bash script for backups on snapshot basis.

The USB hard disk should not be permanently connected, but when the script starts via cronjob and at that moment the hard disk is available, the corresponding ZPOOL should be imported.

In comparison to https://esc-now.de/_/zfs-offsite-backup-auf-eine-externe-festplatte/?lang=en

I am aware that the script in the link is based on Freenas - I am using a current TrueNAS-12.0-U7 now.

The script should run as non-root user and also without "sudo".

Problems / questions:

Does this work with current Truenas at all ? Somehow I have the feeling, as if the CLI should be deliberately not used anymore.

I already tried everything with "Delegating ZFS Permissions" (https://docs.oracle.com/cd/E19253-01/819-5461/gfkco/index.html).

I already fail when importing and exporting the ZPOOLS.

---
Code:

# IMPORT ZPOOL, only works with "sudo".
truenas% zpool import backup
cannot import 'backup': no such pool available

# EXPORT ZPOOL, works only with "sudo
truenas% zpool export backup
cannot unmount '/mnt/backup/data': unmount failed

---

Thanks and best regards
Banane
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Why don't you want the disk to be permanenty connected? Disks don't break from spinning idly. They break when powered off and on again. And with snapshots being read-only and no shares that expose any of the data on that disk to the network ... why?
 

banane

Cadet
Joined
Jan 3, 2022
Messages
3
I want to store the backup media in a different location or even rotate it.

I don't want to question the starting point of my question, I can also accept a "this is not possible with the current Truenas version" as an answer, as long as I learn the reason.

See the linked blogpost, there the ZPOOL is also imported in the script.

My question in summary:

Is it with truenas possible to import and export ZPOOLS on the command line / in a script as non-root?

If yes, what steps do have to take ? :smile:.

I'm happy about any Idea
 
Top