-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-scp.exp
executable file
·75 lines (53 loc) · 1.74 KB
/
backup-scp.exp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/expect
# copyright.c.2021.nic@boet.cc
log_user 0
set timeout 20
set debug 0
set trace 0
set path [file dirname [file normalize [info script]]]
source $path/inc/config.tcl
source $path/inc/common-proc.exp
## manual command example
#
#a10-Active#backup system use-mgmt-port scp://user@10.0.0.1:/home/user/a10.tar.gz
#Password []?
#Do you want to save the remote host information to a profile for later use?[yes/no]no
#System files backup succeeded
#a10-Active#
if {[llength $argv] != 1} {
puts "A10: scp backup configurations\n"
puts "Usage: $argv0 <hostname>"
exit 64
}
set hostname [lindex $argv 0];
set prompt "$hostname*"
#dns resolution is not functional on the shared partition, results in error:
#Backend Error: Failed to backup system files
#resolve our local hostname to the real ip address and pass the in the cli
set scp_server [exec /usr/bin/dig -4 +short $config(scp_host)]
set scp_file "$config(scp_path)/$hostname.tar.gz"
#ping host, proc will exit
if { [myalive $hostname] } {
if {$debug} { puts "## icmp reachable" }
}
#spawn ssh
source $path/inc/ssh-init.exp
if {$debug} { puts "## saving config" }
## make sure we are on the shared part
set part ""
send "active-partition shared\r"
expect -nocase "$prompt#"
#save config
send "write memory all\n"
expect -nocase "$prompt#"
if {$trace} {puts "## remote-url scp://$config(scp_user)@$scp_server:$scp_file" }
send "backup system use-mgmt-port scp://$config(scp_user)@$scp_server:$scp_file\r"
myexpect "Password []?"
send "$config(scp_pass)\r"
myexpect "Do you want to save the remote host information to a profile for later use?"
send "no\r"
myexpect "System files backup succeeded"
#############################################
# logoff
source $path/inc/ssh-close.exp
exit 0