The "syncoid-replicate.sh" script is a Bash script designed for replicating ZFS datasets using the syncoid
tool. It is especially useful for tasks like replicating virtual machine (VM) disks between different ZFS pools, such as from an SSD pool to a mirrored hard drive pool. This script is intended to simplify and automate the replication process.
Before using this script, ensure the following prerequisites are met:
- A working ZFS setup with both the source and destination datasets properly configured.
- The
syncoid
tool should be installed and accessible. You can install it from the syncoid GitHub repository. - Appropriate permissions to run the script and access the ZFS pools.
To use the "syncoid-replicate.sh" script, follow these steps:
- Download the script to your system.
wget https://raw.githubusercontent.com/Mikesco3/syncoid-replicate.sh/main/syncoid-replicate.sh
- Make the script executable using the following command:
chmod +x syncoid-replicate.sh
- Run the script with the source and destination ZFS datasets as arguments. For example, to replicate a dataset from "fast200" to "local-zfs", use the following command:
./syncoid-replicate.sh fast200/vm-vdisk-0 rpool/vm-shadow-of-vdisk-0
Replace fast200/vm-vdiak
with your source and destination datasets.
- The script will use
syncoid
to replicate the dataset, and you will be notified of the replication status (success or failure).
To automate dataset replication, consider using a tool like cron
to schedule the script to run at specific intervals. For example, to run the script daily, you can add a cron job:
- Open your crontab for editing:
crontab -e
- Add a line to schedule the script, providing the full path to the script and the desired schedule. For example, to run the script daily at midnight:
0 0 * * * (/path/to/syncoid-replicate.sh fast200/vm-vmname rpool/vm-vmname) > /dev/null
Running the (command) > /dev/null
supresses regular output and only produces output if there are any error messages
Save the file.
- If you encounter issues with the script, check for errors in the script output and logs.
- Ensure that the required permissions and paths are correctly configured.
- Verify that the syncoid tool is installed and properly configured.
This script is provided as-is and without warranty. Use it at your own discretion and ensure that it aligns with your specific requirements and system setup.