### UFS snapshot
0 1 * * * root /usr/local/sbin/snapshot make -g7 /SRCPATH:Daily
0 2 * * 1 root /usr/local/sbin/snapshot make -g4 /SRCPATH:Weekly
2. 掛載 UFS snapshot 的 shell script
#!/usr/local/bin/bash
PATH=$PATH
CHKPARA=0
if [ -n "$1" ]; then
SSSRCPATH="$1"
shift
else
CHKPARA=1
fi
if [ -n "$1" ]; then
SnapshotName="$1"
shift
else
CHKPARA=1
fi
if [ -n "$1" ]; then
MountPath="$1"
shift
else
CHKPARA=1
fi
if [ $CHKPARA -eq 1 ]; then
echo "Usage: $0 Snapshot_Src_Path SnapshotName MountPath"
echo "Example: $0 /:Weekly.0 /mnt"
exit 1
else
echo "Try to mount $SSSRCPATH:$SnapshotName to $MountPath now."
fi
MC=`df -h |grep $MountPath |wc -l`
if [ -d $SSSRCPATH ]; then
if [ -f $SSSRCPATH/.snap/$SnapshotName ]; then
if [ -d $MountPath ]; then
if [ $MC -gt 0 ]; then
echo "MountPath $MountPath had been mounted!"
else
snapshot mount $SSSRCPATH:$SnapshotName $MountPath
df -h |grep $MountPath
echo "MountPath $MountPath was mounted."
fi
else
echo "MountPath $MountPath does not existed!"
fi
else
echo "Snapshot $SSSRCPATH/.snap/$SnapshotName does not existed!"
fi
else
echo "Snapshot source path $SSSRCPATH does not existed!"
fi
3. 掛載範例
# mkdir -p /SNAPSHOT/Mount/Path/Weekly0
/PATH/TO/mount_UFS_snapshot.sh /SRCPATH Weekly.0 /SNAPSHOT/Mount/Path/Weekly0
4. 卸載 UFS snapshot 的 shell script
#!/usr/local/bin/bash
PATH=$PATH
CHKPARA=0
if [ -n "$1" ]; then
MountPath="$1"
shift
else
CHKPARA=1
fi
if [ $CHKPARA -eq 1 ]; then
echo "Usage: $0 MountPath"
echo "Example: $0 /mnt"
exit 1
else
echo "Try to umount $MountPath now."
fi
MC=`df -h |grep $MountPath |wc -l`
if [ -d $MountPath ]; then
if [ $MC -gt 0 ]; then
snapshot umount $MountPath
df -h |grep $MountPath
echo "MountPath $MountPath had been umounted!"
else
echo "MountPath $MountPath had not been mounted!"
fi
else
echo "MountPath $MountPath does not existed!"
fi
5. 卸載範例
/PATH/TO/umount_UFS_snapshot.sh /SNAPSHOT/Mount/Path/Weekly0
6. UFS 做 snapshot 速度還蠻慢的. (相較於 ZFS 的快速完成 snapshot)
參考資料
FreeBSD UFS/ZFS Snapshot Management Environment
No comments:
Post a Comment