最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

備份shell腳本實例代碼

 更新時間:2013年02月11日 15:23:10   作者:  
備份shell腳本一例,有需要的朋友可以參考下
1、backup_run.sh
復(fù)制代碼 代碼如下:

    #!/bin/sh
    # backup_run
    # script to run the backups
    # loads in a setting file for the user to change
    SOURCE=/home/bob/backup.defaults
    check_source()
    {
        # check_source
        # can we load the file
        # backup.defaults is the source file containing config/functions
        # make sure your path includes this directory you are runing from
        if [ -r $SOURCE ];then
          . $SOURCE # load $source
        else
            echo "`basename $0`: cannot locate default file"
            exit 1
        fi
    }
    header()
    {
        # header
        USER=`whoami`
        MYDATE=`date +%A" "%e" of "%B-%Y`
        clear
        cat << HH
        User: $USER $MYDATE
                    NETWORK SYSTEM BACKUP
                    =====================
    HH
    }
    change_settings()
    {
        # change_settings
        # let the user see the default settings..
        header
        echo "Valid Entries Are..."
        echo "Tape Device: rmt0,rmt1,rmt3"
        echo "Mail Admin:yes,no"
        echo "Backup Type: full,normal,sybase "
        while :
        do
            echo -n -c "\n\n Tape Device To Be Used For This Backup [$_DEVICE] :"
            read T_DEVICE
            : ${T_DEVICE:=$_DEVICE}
            case $T_DEVICE in
                rmt0|rmt1|rmt3) break

                *) echo "The device are either...rmt0,rmt1,rmt3"

            esac
        done
        # if the user hits return on any of the fields, the default value will be used
        while :
        do
            echo -n "Mail Admin When Done [$_INFORM] : "
            read T_INFORM
            : ${T_INFORM:=$_INFORM}
            case $T_INFORM in
                yes|Yes) break

                no|No) break

                *) echo "The choices are yes,no"

            esac
        done
        while :
        do
            echo -n "Backup Type [$_TYPE] :"
            read T_TYPE
            : ${T_TYPE:=$_TYPE}
            case $T_TYPE in
                Full|full) break

                Normal|normal) break

                Sybase|sybase) break

                *) echo "The choices are either ... full,normal,sybase"
            esac
        done
        # re-assign the temp varialbes back to original variables that
        # were loaded in
        _DEVICE=$T_DEVICE;_INFORM=$T_INFORM;_TYPE=$T_TYPE
    }
    show_settings()
    {
        # display current settings
        cat << HH
                    Default Settings Are...
                Tape Device To Be Used : $_DEVICE
                Mail Admin When Done : $_INFORM
                Type Of Backup : $_TYPE
                Log File Of Backup : $_LOGFILE
    HH
    }
    get_code()
    {
        # users get 3 attempts at entering the correct code
        # _CODE is loaded in from the source file
        clear
        header
        _COUNTER=0
        echo "YOU MUST ENTER THE CORRECT CODE TO BE ABLE TO CHANGE DEFAULT SETTINGS"
        while :
        do
            _COUNTER=`expr $_COUNTER + 1`
            echo -n "Enter the code to change the settings: "
            read T_CODE
            # echo $_COUNTER
            if [ "$T_CODE" = "$_CODE" ];then
                return 0
            else
                if [ "$_COUNTER" -gt 3 ];then
                    echo "Sorry incorrect code entered, you cannot change the settings..."
                    return 1
                fi
            fi
        done
    }
    check_drive()
    {
        # make sure we can rewind the tape
        mt -f /dev/$_DEVICE rewind > /dev/null 2>&1
        if [ $? -ne 0 ];then
            return 1
        else
            return 0
        fi
    }
    #====================== main =======================
    # can we source the file
    check_source
    header
    # display the loaded in variables
    show_settings
    # ask user if he/she wants to change any settings
    if continue_prompt "Do you wish To Change Some of The System Defaults" "Y";
    then
        echo $?   
        # yes then enter code name
        if get_code;then
            # change some settings
            change_settings
        fi
    fi
    #------------------ got settings... now do backup
    if check_drive;then
        echo "tape OK..."
    else
        echo "Cannot rewind the tape..Is it in the tape drive???"
        echo "check it out"
        exit 1
    fi
    # file system paths to backup
    case $_TYPE in
        Full|full)
            BACKUP_PATH="sybase syb/suppor etc var bin apps usr/local"

        Normal|normal)
            BACKUP_PATH="etc var bin apps usr/local"

        Sybase|sybase)
            BACKUP_PATH="sybase syb/suppor"

    esac
    # now for backup
    cd /
    echo "Now starting backup......"
    find $BACKUP_PATH -print | cpio -ovB -O /dev/$_DEVICE >> $_LOGFILE 2>&1
    # if the above cpio does not work on your system try cpio below, instead
    # find $BACKUP_PATH -print | cpio -ovB > /dev/$_DEVICE >> $_LOGFILE 2>&1
    # to get more information on the tape change -ovB to -ovcC66536
    if [ "$_INFORM" = "yes" ];then
        echo "Backup finished check the log file" | mail admin
    fi

2、backup.defaults
復(fù)制代碼 代碼如下:

    #!/bin/sh
    # backup.defaults
    # configuration default file for network backups
    # edit this file at your own
    # name backup.defaults
    # --------------------------------------------
    # not necessary for the environments to be in quotes.. but
    _CODE="comet"
    _LOGFILE="/appdva/backup/log.`date +%y%m%d`"
    _DEVICE="rmt0"
    _INFORM="yes"
    _TYPE="Full"
    #---------------------------------------------
    continue_prompt()
    {
        # continue_prompt
        # to call: continue_prompt "string to display" default_answer
        _STR=$1
        _DEFAULT=$2
        # check we have the right params
        if [ $# -lt 1 ];then
            echo "continue_prompt: I need a string to display"
            return 1
        fi
        while :
        do
            echo -n "$_STR [Y..N] [$_DEFAULT]:"
            read _ANS
            if [ "$_ANS" = "" ];then
                : ${_ANS:=$_DEFAULT}
                case $_ANS in
                    Y) return 0

                    N) return 1

                esac
            fi
            # user has selected something
            case $_ANS in
                y|Y|Yes|YES)
                    return 0

                n|N|No|NO)
                    return 1

                *) echo "Answer either Y or N, default is $_DEFAULT"

            esac
            echo $_ANS
        done
    }

3、運行:
復(fù)制代碼 代碼如下:

$./backup_run.sh backup.defaults

相關(guān)文章

  • Shell根據(jù)web日志計算平均連接時間功能

    Shell根據(jù)web日志計算平均連接時間功能

    這篇文章主要介紹了Shell根據(jù)web日志計算平均連接時間功能,本文給出了原代碼和自己修改后的代碼,需要的朋友可以參考下
    2014-12-12
  • shell腳本中set?-e選項作用范圍小結(jié)

    shell腳本中set?-e選項作用范圍小結(jié)

    本文主要介紹了shell腳本中set?-e選項作用范圍小結(jié),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06
  • linux find命令將查找到的文件批量刪除方法

    linux find命令將查找到的文件批量刪除方法

    這篇文章主要介紹了linux find命令將查找到的文件批量刪除,文中給大家補充介紹了Linux中find三種刪除方式,常用于crontab定時任務(wù)和shell腳本,需要的朋友可以參考下
    2022-12-12
  • shell在指定目錄下批量執(zhí)行sql腳本的實例

    shell在指定目錄下批量執(zhí)行sql腳本的實例

    今天小編就為大家分享一篇shell在指定目錄下批量執(zhí)行sql腳本的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • Shell編程之免交互的實現(xiàn)示例

    Shell編程之免交互的實現(xiàn)示例

    對于Linux操作系統(tǒng)中,有許多操作都會觸及到交互,本文主要介紹了Shell編程之免交互,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-06-06
  • Linux下快速比較兩個目錄的不同(多種方法)

    Linux下快速比較兩個目錄的不同(多種方法)

    這篇文章主要介紹了Linux下快速比較兩個目錄的不同,本文給大家?guī)砹硕喾N方法,非常不錯,具有一定的參考借鑒價值,感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧
    2018-05-05
  • Linux自定義防誤刪腳本的思路與測試

    Linux自定義防誤刪腳本的思路與測試

    相信很多朋友都遇到過在linux下誤刪除文件的時候,此刻的心中仿佛有無數(shù)的羊駝在奔騰,下面這篇文章主要給大家介紹了關(guān)于Linux自定義防誤刪腳本的思路與測試的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • 如何解決 shell 腳本重復(fù)執(zhí)行的問題

    如何解決 shell 腳本重復(fù)執(zhí)行的問題

    假如執(zhí)行備份腳本消耗的時間遠大于設(shè)置的備份間隔的話,系統(tǒng)會出現(xiàn)多個同時在執(zhí)行腳本的Bash實例,會占用大量的系統(tǒng)資源,進而影響正常業(yè)務(wù)程序的運行,那如何解決上述shell腳本重復(fù)執(zhí)行的問題呢,本文將要介紹的 flock 命令可以解決這個問題
    2021-05-05
  • shell讀取配置文件的方式sed命令詳解

    shell讀取配置文件的方式sed命令詳解

    在編寫啟動腳本時,涉及到讀取配置文件,特地記錄下shell腳本讀取啟動文件的方式,這篇文章主要介紹了shell讀取配置文件-sed命令,需要的朋友可以參考下
    2023-04-04
  • Linux 終端中命令輸出保存到文件中的方法

    Linux 終端中命令輸出保存到文件中的方法

    這篇文章主要介紹了如何將 Linux 終端中命令的輸出保存到文件中實例操作,操作步驟非常詳細,有需要的小伙伴可以按步驟來研究下吧
    2020-12-12

最新評論

海丰县| 古丈县| 滦平县| 三河市| 牡丹江市| 兴国县| 永泰县| 泌阳县| 娄底市| 旌德县| 潍坊市| 当雄县| 包头市| 新平| 定远县| 溧阳市| 怀柔区| 定边县| 吴旗县| 沁阳市| 沙湾县| 札达县| 永修县| 饶阳县| 咸丰县| 肇源县| 临安市| 德格县| 云和县| 昂仁县| 赞皇县| 天门市| 苗栗市| 封丘县| 巴南区| 财经| 青川县| 河津市| 承德市| 崇左市| 肥乡县|