[Level 3] Clone ZFS Permissions
One day, someone ask me how to clone ZFS permissions from one ZFS file system to another ZFS file system.
It seems that zfs command doesnot support the permission like getfacl setfacl to clone the file system permissions.
Therefore I try to write a script to implement that,
please refer to the following code.
#!/usr/bin/bash
showUsage() {
cat <<EOF
Usage:
$0 source_zfs target_zfs
Ex.
$0 rpool/fs1 karajon/fs2
EOF
}
##################################### main
sSZFS=$1
sTZFS=$2
declare -i fPermSet=0
declare -i fLocalPerm=0
zfs allow $sSZFS | while read s
do
( echo $s | grep "^---- Permissions on " > /dev/null ) && continue
( echo $s | grep "^Permission sets:$" > /dev/null ) && fPermSet=1 && fLocalPerm=0 && continue
( echo $s | grep "^Local+Descendent permissions:$" > /dev/null ) && fLocalPerm=1 && fPermSet=0 && continue
if [ $fPermSet -eq 1 ]
then
echo "zfs allow -s $s $sTZFS"
zfs allow -s $s $sTZFS
elif [ $fLocalPerm -eq 1 ]
then
echo "zfs allow -u ${s#user } $sTZFS"
zfs allow -u ${s#user } $sTZFS
fi
done
showUsage() {
cat <<EOF
Usage:
$0 source_zfs target_zfs
Ex.
$0 rpool/fs1 karajon/fs2
EOF
}
##################################### main
sSZFS=$1
sTZFS=$2
declare -i fPermSet=0
declare -i fLocalPerm=0
zfs allow $sSZFS | while read s
do
( echo $s | grep "^---- Permissions on " > /dev/null ) && continue
( echo $s | grep "^Permission sets:$" > /dev/null ) && fPermSet=1 && fLocalPerm=0 && continue
( echo $s | grep "^Local+Descendent permissions:$" > /dev/null ) && fLocalPerm=1 && fPermSet=0 && continue
if [ $fPermSet -eq 1 ]
then
echo "zfs allow -s $s $sTZFS"
zfs allow -s $s $sTZFS
elif [ $fLocalPerm -eq 1 ]
then
echo "zfs allow -u ${s#user } $sTZFS"
zfs allow -u ${s#user } $sTZFS
fi
done
Wish this helps.
regards,
Stanley Huang
Comments
Post a Comment