Automation, Backup Config With Paramiko

 

Masih dengan  topologi  yang sama, kali ini akan melakukan backup config menggunakan automation!

berikut adalah scriptnya:

import paramiko import time  
  
ip_address = "192.168.10.2" username = "fathan"  
password = "fathanrafaa"  
  
ssh_client = paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_client.connect(hostname=ip_address,username=username, password=password)  
  
print "Success login to {0}".format(ip_address) conn = ssh_client.invoke_shell()  
  
conn.send("terminal length 0\n")  
conn.send("show run\n") time.sleep(5)  
 
output = conn.recv(65535)  
  output_file=open("{0}.cfg".format(ip_address),"w") output_file.write(output)  output_file.close()  
print "Config in {0} saved!!".format(ip_address)    ssh_client.close()  

Kemudian kita input kedalam ubuntu.

root@NetworkAutomation-1:~# cp paramiko1.py backup.py root@NetworkAutomation-1:~# nano backup.py root@NetworkAutomation-1:~# cat backup.py  import paramiko import time  
  
ip_address = "192.168.10.2" username = "fathan"  
password = "fathanrafaa"  
  
ssh_client = paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_client.connect(hostname=ip_address,username=username, password=password)  
  
print "Success login to {0}".format(ip_address) conn = ssh_client.invoke_shell()  
  
conn.send("terminal length 0\n")  
conn.send("show run\n") time.sleep(5)  
 
output = conn.recv(65535)  
  output_file=open("{0}.cfg".format(ip_address),"w") output_file.write(output)  output_file.close()  
print "Config in {0} saved!!".format(ip_address)    ssh_client.close()  

Jika sudah tinggal kita jalankan!

root@NetworkAutomation-1:~# python backup.py 
Success login to 192.168.10.2
Config in 192.168.10.2 saved!!  
root@NetworkAutomation-1:~# ls | grep .cfg 192.168.10.2.cfg  
SUSKES!!!

File tersebut disimpan dengan nama 192.168.10.2.cfg

Untuk melihat isinya ketikkan:

root@NetworkAutomation-1:~# more 192.168.10.2.cfg  
  
R1#terminal length 0 R1#show run  Building configuration...  
  
Current configuration : 1280 bytes  
!  
version 12.4  
service timestamps debug datetime msec service timestamps log datetime msec  no service password-encryption  
!  
hostname R1  
!  
boot-startmarker boot-endmarker  --More--(18%)  

Seperti itulahh konfigurasi nyaa

Komentar

Postingan populer dari blog ini

LAB 11. BGP Dual Homing – ISP sama