How to take the tar backup files form remote server to local server - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to take the tar backup files form remote server to local server (/thread-34281.html) |
How to take the tar backup files form remote server to local server - sivareddy - Jul-14-2021 import os, subprocess, psutil import sys import tarfile COMMAND="ls -la" HOST=input("Please enter old server: ") ssh_option="-o StrictHostKeyChecking=no" ssh = subprocess.Popen(["ssh", ssh_option,"%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE) result = ssh.stdout.readlines() if result == []: error = ssh.stderr.readlines() print >>sys.stderr, "ERROR: %s" % error print(" if test") else: COMMAND1=subprocess.call(['python tartest.py']) #i what to run command script on remote server and take backupfiles in to local server ssh_tar_baekup = subprocess.Popen(["ssh", ssh_option,"%s" % HOST,COMMAND1],shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) ----------------------- cat tartest.py import os import subprocess from contextlib import closing import sys import tarfile with closing(tarfile.open("/var/tmp/back_siva/siva.tar.gz","w:gz")) as tar: for file in ["/var/tmp/back_siva/yp.conf","/var/tmp/back_siva/ypserv.conf"]: tar.add(os.path.basename(file)) ----------------------------------------------- Please enter old server: xxxxxx Traceback (most recent call last): File "testsiva1.py", line 17, in <module> COMMAND1=subprocess.call(['python tartest.py']) File "/usr/lib64/python2.7/subprocess.py", line 524, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__ errread, errwrite) File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory |