본문 바로가기
운영_설치/리눅스_유닉스

zfs 자동 스냅샷 스크립트

by 써드아이 2018. 6. 6.



/root/Script/zfs_snapshot.sh



#!/bin/bash


POOL_LIST="pluto0"
#FS_LIST="home apps photos repository plexlibrary tmp tmp_portage"
FS_LIST=

DAILY_SS="home plexlibrary"
WEEKLY_SS="apps photos repository"
MONTHLY_SS="tmp tmp_portage"


function date_str() { echo $(date +%Y.%m.%d-%H:%M:%S); }

function snapshot()
{
        for temp in $FS_LIST;
        do
                zfs snapshot $POOL_LIST/$temp@$(date_str)
                #echo $POOL_LIST/$temp@$(date_str)
        done
}

#
#
#

function main()
{
#PN=$(echo $0 | sed 's/.\///')

PN=$(basename $0)

echo $PN

if [ $PN = "daily_snapshot.sh" ]; then
        FS_LIST=$DAILY_SS
elif [ $PN = "weekly_snapshot.sh" ]; then
        FS_LIST="$DAILY_SS $WEEKLY_SS"
elif [ $PN = "monthly_snapshot.sh" ]; then
        FS_LIST="$DAILY_SS $WEEKLY_SS $MONTHLY_SS"
fi

snapshot
}


#
#
#
main


chmod 755 zfs_snapshot.sh

ln -s /root/Script/zfs_snapshot.sh /etc/cron.daily/daily_snapshot.sh

ln -s /root/Script/zfs_snapshot.sh /etc/cron.daily/weekly_snapshot.sh

ln -s /root/Script/zfs_snapshot.sh /etc/cron.daily/monthly_snapshot.sh





* 스냅샷 확인 명령


# zfs list -t snapshot