Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python -tt
- import paramiko
- import socket
- import time
- # Configuration
- hostname="XXX"
- sshPort="XXX"
- sshUser="remotebackup"
- sshKeyLocation="/Users/chrisk/.ssh/id_rsa"
- sshTimeout=20
- def buildSshConnection():
- cmd = 'mysqldump -u xxx --password="XX" xxx > xxx.sql'
- ssh = paramiko.SSHClient()
- socket_timeout = socket.timeout
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- try:
- ssh.connect(hostname, username='remotebackupguy',
- timeout=sshTimeout, port=30001,
- key_filename=sshKeyLocation)
- except socket.timeout, e:
- print "Took longer than " + str(sshTimeout) + " to establish a connection, skipping this node."
- stdin, stdout, stderr = ssh.exec_command(cmd)
- ftp = ssh.open_sftp()
- timestamp = time.time()
- ftp.get('osxdaily.sql', 'osxdaily-' + str(timestamp) + '.py')
- ftp.close()
- stdin, stdout, stderr = ssh.exec_command("rm osxdaily.sql")
- buildSshConnection()
Add Comment
Please, Sign In to add comment