This script is for converting directories into ZFS datasets on an Unraid server and runs in the User Scripts plugin. It's proficient in processing appdata from Docker Containers, vdisks from VMs and various other locations within a single run. For directories storing appdata or VM vdisk data, the script is able to detect active containers or VMs that are using these folders. It will automatically stop these containers or VMs prior to initiating the conversion. Set to operate on a schedule via Unraid user scripts, this tool then can continue to monitor datasets, making certain that their associated child folders remain as datasets. This is especially valuable when, for instance, installing a new container: its appdata will be converted automatically. Such functionality is invaluable for users keen on snapshotting individual containers, VMs, or various data structures.
The script will do the following
Before using the script, ensure the following:
dry_run
: Set to "yes" if you only want to simulate a run without making any changes. Set to "no" to actually run the conversion.If you want the script to process Docker appdata -
should_process_containers
: Set to "yes" this tells the script the location is container appdata so it can safely deal with it.source_pool_where_appdata_is
: Specify the source pool containing the appdata.source_dataset_where_appdata_is
: Specify the source dataset for appdata.If you want the script to process VM vdisks -
should_process_vms
: Set to "yes" this tells the script the location contains vdisks so it can safely deal with it.source_pool_where_vm_domains_are
: Specify the source pool containing the VM domains.source_dataset_where_vm_domains_are
: Specify the source dataset for VM domains.vm_forceshutdown_wait
: Duration (in seconds) to wait before force stopping a VM if it doesn't shut down gracefully.This is where you can add other datasets (non appdata ot vm ones) to be processed by the script:
source_datasets_array
: Specify custom paths in the format pool/dataset, e.g., "tank/mydata".After you have configured the script, follow these steps:
Simplified Working Principle:
Initialization:
dry_run
: If set to "yes", the script won't make any real changes but will only output what would happen.should_process_containers
: If set to "yes", the script will process and convert Docker containers' appdata.should_process_vms
: If set to "yes", the script will process and convert Virtual Machines' disk folders.Dataset Path Check:
source_datasets_array
.Utilities:
find_real_location()
: Identifies the actual physical location of a given path.is_zfs_dataset()
: Checks if a given path is a ZFS dataset.Stopping Containers:
Stopping VMs:
Creating Datasets:
Restarting Containers & VMs:
Logging:
Key Concepts:
Bind Mount: A type of mount where a source directory or file is superimposed onto a destination, making its contents accessible from the destination. Used heavily in Unraid Docker templates.
ZFS Dataset: A ZFS dataset can be thought of as a sort of advanced folder with features like compression, quota, and snapshot capabilities.
rsync: A fast, versatile utility for copying files and directories. It's often used for mirroring and backups. Keeps timestamps and permissions etc
How script Works:
CONTRIBUTE TO THE PROJECT
Your insights and expertise can make a difference! If you've identified improvements or have suggestions for the script, I'd truly appreciate your contributions. Help me make this tool even better.
I'm open to feedback, code enhancements, or new ideas.
DISCLAIMER
While this script has been thoroughly tested and is believed to be reliable, unforeseen edge cases may arise. By using this software, you acknowledge potential risks and agree to use it at your own discretion. The author assumes no responsibility for any unintended outcomes.
Use wisely and responsibly!!!