-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_backup.py
More file actions
55 lines (43 loc) · 1.38 KB
/
config_backup.py
File metadata and controls
55 lines (43 loc) · 1.38 KB
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
#Simple Script to login to the NMS (Network Management System) Device and get the config db file and store it in a backup
#server using pexpect.
import pexpect
import sys
from datetime import date
IP = raw_input("Enter the IP of the vmanage: ")
username = raw_input("Enter the username: ")
password = raw_input("Enter the password: ")
backup_server_IP = raw_input("Enter the IP of the backup server: ")
backup_server_username = raw_input("Enter the username for the backup server: ")
backup_server_Password = raw_input("Enter the password for the backup server: ")
today_date = date.today()
#try:
c = pexpect.spawn('ssh admin@%s' %IP)
c.timeout = 4
c.expect("password: ")
c.logfile = sys.stdout
#except pexpect.TIMEOUT:
# raise Exception("Fail")
c.sendline(password)
c.expect('#')
c.sendline('request nms configuration-db backup path /home/admin/%s' %today_date )
c.timeout = 1000
c.expect('#')
c.sendline('request execute vpn 512 scp %s.tar.gz me@%s:/home/%s' %(today_date, backup_server_IP,backup_server_username) )
i = c.expect(['yes/no ', 'password:'])
if i == 0:
c.sendline('yes')
c.timeout = 100
c.expect('password: ')
c.sendline(backup_server_Password)
c.timeout = 1000
c.expect('#')
elif i == 1:
c.sendline(backup_server_Password)
c.timeout = 1000
c.expect('#')
c.sendline('vshell')
c.expect('$')
c.sendline('rm - rf %s.tar.gz' %today_date)
c.timeout = 100
c.expect('$')
c.close()