?? backup.exp
字號(hào):
#!/usr/local/bin/expect# -*- Mode: Tcl -*- # backup.exp# # Description : Tests NDMP server backup functionality.# # usage: backup.exp local|tcp mover|data datahost ?moverhost?# where: local|tcp specifies the data connection type.# mover|data specifies whether the mover or data# server is responsible for initiating the data# connection.# datahost is the name of the host to be backed up.# moverhost is the name of the host that will # run the mover and write the data to tape.# moverhost is only used if the connection type is# tcp. If the connection type is local or moverhost# is not specified, then the data is backed up# to datahost.## <datahost>.tcl and <moverhost>.tcl must must exist and# contain the system variable initializations appropriate# to the host. See system.tcl for an example.# Replace <datahost> and <moverhost> with actual hostnames.## Copyright (c) 1998 Intelliguard, Network Appliance. All Rights Reserved.## $Id: backup.exp,v 1.3 1998/05/26 03:52:09 tim Exp $# if {[llength $argv] < 3} { puts "usage: $argv0 local|tcp mover|data datahost ?moverhost?" exitn}switch -exact -- [lindex $argv 0] { local { set connection_type local } tcp { set connection_type tcp } default { puts "usage: $argv0 local|tcp mover|data datahost ?moverhost?" exit }}switch -exact -- [lindex $argv 1] { mover { set initiator mover } data { set initiator data } default { puts "usage: $argv0 local|tcp mover|data datahost ?moverhost?" exit }} set data_host [lindex $argv 2]source $data_host.tclset data_auth_cmd $auth_cmdset data_filesystem $filesystemif {$connection_type == "local" || [llength $argv] < 4} { set mover_host $data_host} else { set mover_host [lindex $argv 3] source $mover_host.tcl}set mover_auth_cmd $auth_cmdset mover_tape_device $tape_deviceset timeout 60# start the data serverspawn ../ndmpc -h $data_hostset data_id $spawn_idexpect { -i $data_id -re "(Error)|(ERROR)" { exit } -i $data_id "ndmpc>"}#send -i $data_id "ndmpc_option fh_terse \r"send -i $data_id "ndmpc_option fh_verbose \r"expect { -i $data_id -re "(Error)|(ERROR)" { exit } -i $data_id "ndmpc>"}send -i $data_id "connect_open 3\r"expect { -i $data_id -re "(Error)|(ERROR)" { exit } -i $data_id "ndmpc>"}send -i $data_id "$data_auth_cmd \r"expect { -i $data_id -re "(Error)|(ERROR)" { exit } -i $data_id "ndmpc>"}# Create another NDMP connection for the mover if using a TCP connection# between the data server and the mover.if {$connection_type == "tcp"} { spawn ../ndmpc -h $mover_host -p 10000 set mover_id $spawn_id expect { -i $mover_id -re "(Error)|(ERROR)" { exit } -i $mover_id "ndmpc>" } send -i $mover_id "connect_open 3\r" expect { -i $mover_id -re "(Error)|(ERROR)" { exit } -i $mover_id "ndmpc>" } send -i $mover_id "$mover_auth_cmd \r" expect { -i $mover_id -re "(Error)|(ERROR)" { exit } -i $mover_id "ndmpc>" }} else { set mover_id $data_id}# Configure the mover and open the tape device.send -i $mover_id "mover_set_record_size 61440 \r"expect { -i $mover_id -re "(Error)|(ERROR)" { exit } -i $mover_id "ndmpc>"}send -i $mover_id "tape_open $mover_tape_device \r"expect { -i $mover_id -re "(Error)|(ERROR)" { exit } -i $mover_id "ndmpc>"}send -i $mover_id "tape_mtio rew \r"expect { -i $mover_id -re "(Error)|(ERROR)" { exit } -i $mover_id "ndmpc>"}# Establish the data connection between the mover and data server.if { $initiator == "mover" } { send -i $data_id "data_listen $connection_type \r" if { $connection_type == "local" } { expect { -i $data_id -re "connect_addr LOCAL.*\n" { exp_continue } -i $data_id -re "(Error)|(ERROR)" { exit } -i $data_id "ndmpc>" } } else { expect { -i $data_id -re "TCP (0x\[0-9a-f]*) (\[0-9]*).*\n" { set ipaddr $expect_out(1,string) set port $expect_out(2,string) } -i $data_id -re "(Error)|(ERROR)" { exit } -i $data_id "ndmpc>" } }} else { send -i $mover_id "mover_listen read $connection_type \r" if { $connection_type == "local" } { expect { -i $mover_id -re "connect_addr LOCAL.*\n" { exp_continue } -i $mover_id -re "(Error)|(ERROR)" { exit } -i $mover_id "ndmpc>" } } else { expect { -i $mover_id -re "TCP (0x\[0-9a-f]*) (\[0-9]*).*\n" { set ipaddr $expect_out(1,string) set port $expect_out(2,string) } -i $mover_id -re "(Error)|(ERROR)" { exit } -i $mover_id "ndmpc>" } }}if { $initiator == "mover" } { if { $connection_type == "local" } { send -i $mover_id "mover_connect read local \r" } else { send -i $mover_id "mover_connect read tcp $ipaddr $port \r" } expect { -i $mover_id -re "(Error)|(ERROR)" { exit } -i $mover_id "ndmpc>" }} else { if { $connection_type == "local" } { send -i $data_id "data_connect local \r" } else { send -i $data_id "data_connect tcp $ipaddr $port \r" } expect { -i $data_id -re "(Error)|(ERROR)" { exit } -i $data_id "ndmpc>" }}send -i $data_id "add_env FILESYSTEM $data_filesystem \r"expect { -i $data_id -re "(Error)|(ERROR)" { exit } -i $data_id "ndmpc>"}#send -i $data_id "add_env HIST false \r"send -i $data_id "add_env HIST true \r"expect { -i $data_id -re "(Error)|(ERROR)" { exit } -i $data_id "ndmpc>"}send -i $data_id "data_start_backup dump \r"expect { -i $data_id -re "(Error)|(ERROR)" { exit } -i $data_id "ndmpc>"}set data_done 0set mover_done 0set doMoverStop 0set doDataStop 0set doTapeMtio 0set doTapeClose 0set checkDataDone 0set checkMoverDone 0expect { -i $any_spawn_id "Error" { send -i $data_id "exit\r" if {$mover_id != $data_id} { send -i $mover_id "exit\r" } exit } -i $any_spawn_id "ndmpc>" { if {$doDataStop} { send -i $data_id "data_stop \r" set doDataStop 0 set checkMoverDone 1 exp_continue } if {$doMoverStop} { send -i $mover_id "mover_stop \r" set doMoverStop 0 set doTapeMtio 1 exp_continue } if {$doTapeMtio} { send -i $mover_id "tape_mtio weof \r" set doTapeMtio 0 set doTapeClose 1 exp_continue } if {$doTapeClose} { send -i $mover_id "tape_close \r" set doTapeClose 0 set checkDataDone 1 exp_continue } if {$checkDataDone} { if {$data_done == 1} { exit } set checkDataDone 0 set mover_done 1 # Wait for notification that data server has halted. exp_continue } if {$checkMoverDone} { if {$mover_done} { exit } set checkMoverDone 0 set data_done 1 # Wait for notification that mover has halted. exp_continue } exp_continue } -i $data_id -re "Received notify_data_halted.*\n$" { send -i $data_id "data_get_state \r" set doDataStop 1 exp_continue } -i $mover_id -re "Received notify_mover_halted.*\n$" { send -i $mover_id "mover_get_state \r" set doMoverStop 1 exp_continue } timeout { send -i $data_id "data_get_state\r" send -i $mover_id "mover_get_state\r" exp_continue }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -