欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

備份shell腳本實(shí)例代碼

 更新時(shí)間: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、運(yùn)行:
復(fù)制代碼 代碼如下:

$./backup_run.sh backup.defaults

相關(guān)文章

  • Shell中的${}、##和%%使用范例

    Shell中的${}、##和%%使用范例

    這篇文章主要介紹了Shell中的${}、##和%%使用范例,本文給出了不同情況下得到的結(jié)果,需要的朋友可以參考下
    2015-04-04
  • shell一鍵部署Zabbix的實(shí)現(xiàn)步驟

    shell一鍵部署Zabbix的實(shí)現(xiàn)步驟

    本文主要介紹了shell一鍵部署Zabbix的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-02-02
  • linux 獲取某個(gè)日期對(duì)應(yīng)的月末日期方法

    linux 獲取某個(gè)日期對(duì)應(yīng)的月末日期方法

    今天小編就為大家分享一篇linux 獲取某個(gè)日期對(duì)應(yīng)的月末日期方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • Shell中變量作用域的介紹與使用命令

    Shell中變量作用域的介紹與使用命令

    作用域是我們?cè)谌粘W(xué)習(xí)或者工作中經(jīng)常會(huì)遇到的一個(gè)問題,下面這篇文章主要給大家介紹了關(guān)于Shell中變量作用域的相關(guān)資料,文中介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面跟著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-08-08
  • shell周期差量備份文件夾的實(shí)現(xiàn)代碼

    shell周期差量備份文件夾的實(shí)現(xiàn)代碼

    這篇文章主要介紹了shell周期差量備份文件夾的實(shí)現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • shell腳本殺死指定端口進(jìn)程的實(shí)現(xiàn)示例

    shell腳本殺死指定端口進(jìn)程的實(shí)現(xiàn)示例

    隨著越來越廣泛的Linux系統(tǒng)使用,如何輕松殺死指定程序端口成為了很多系統(tǒng)管理員最迫切關(guān)心的問題,本文就詳細(xì)的介紹一下如何實(shí)現(xiàn),感興趣的可以了解一下
    2023-10-10
  • awk正則表達(dá)式和內(nèi)置函數(shù)的使用方法實(shí)例詳解

    awk正則表達(dá)式和內(nèi)置函數(shù)的使用方法實(shí)例詳解

    這篇文章主要介紹了awk正則表達(dá)式和內(nèi)置函數(shù)的使用方法實(shí)例詳解,本文總結(jié)了15個(gè)使用例子,需要的朋友可以參考下
    2014-12-12
  • Linux重命名文件和文件夾的兩種方法

    Linux重命名文件和文件夾的兩種方法

    這篇文章主要介紹了Linux重命名文件和文件夾的兩種方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-12-12
  • 備份shell腳本實(shí)例代碼

    備份shell腳本實(shí)例代碼

    備份shell腳本一例,有需要的朋友可以參考下
    2013-02-02
  • Shell腳本中通過正則表達(dá)式匹配IP地址

    Shell腳本中通過正則表達(dá)式匹配IP地址

    這篇文章主要介紹了Shell腳本中通過正則表達(dá)式匹配IP地址,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-05-05

最新評(píng)論