Guest User

Untitled

a guest
Apr 16th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. #!/usr/bin/python -tt
  2.  
  3. import paramiko
  4. import socket
  5. import time
  6.  
  7. # Configuration
  8. hostname="XXX"
  9. sshPort="XXX"
  10. sshUser="remotebackup"
  11. sshKeyLocation="/Users/chrisk/.ssh/id_rsa"
  12. sshTimeout=20
  13.  
  14. def buildSshConnection():
  15.         cmd = 'mysqldump -u xxx --password="XX" xxx > xxx.sql'
  16.         ssh = paramiko.SSHClient()
  17.         socket_timeout = socket.timeout
  18.         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  19.         try:
  20.             ssh.connect(hostname, username='remotebackupguy',
  21.                         timeout=sshTimeout, port=30001,
  22.                         key_filename=sshKeyLocation)
  23.         except socket.timeout, e:
  24.             print "Took longer than " + str(sshTimeout) + " to establish a connection, skipping this node."
  25.         stdin, stdout, stderr = ssh.exec_command(cmd)
  26.         ftp = ssh.open_sftp()
  27.         timestamp = time.time()
  28.         ftp.get('osxdaily.sql', 'osxdaily-' + str(timestamp) + '.py')
  29.         ftp.close()
  30.         stdin, stdout, stderr = ssh.exec_command("rm osxdaily.sql")
  31.  
  32.  
  33. buildSshConnection()
Add Comment
Please, Sign In to add comment