Sharing this small snippet here. The use case is I’m running HAOS as a VM on a ZFS zvol and I wanted to be able to copy the daily backups to a dedicated ZFS dataset that is automatically snapshotted and copied elsewhere.
The automated backup on HAOS happens at 5AM and the script is intended to be executed at 7 AM via cron on the underlying OS.
#!/bin/bash
ORIG=/root/haos/data/supervisor/backup/
DESTINATION=/tank/home-assistant-backups/
# Get the partitions for the zvol
/usr/sbin/kpartx -a /dev/zvol/ssdpool/haos
# Mount the one with the backups as read-only
/usr/bin/mount -o ro /dev/mapper/haos8 /root/haos/data
# Copy all those files
/usr/bin/find ${ORIG} -maxdepth 1 -iname "*.tar" -exec cp -a "{}" ${DESTINATION} \;
# cp -a /root/haos/data/supervisor/backup/* ${DESTINATION}
# Umount the partition
/usr/bin/umount /root/haos/data
# Wipe the kernel entries for the zvol partitions
/usr/sbin/kpartx -d /dev/zvol/ssdpool/haos
# Delete the oldest
/usr/bin/find ${DESTINATION} -maxdepth 1 -mtime +30 -exec rm {} \;
HTH!