Python Forum
How to take the tar backup files form remote server to local server
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to take the tar backup files form remote server to local server
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Running script from remote to server invisiblemind 4 724 Mar-28-2025, 07:57 AM
Last Post: buran
  client A to server B connects but client B to server A doesnt connect gerald 1 778 Aug-17-2024, 07:33 AM
Last Post: Gribouillis
Exclamation Date format convert problem for SQL server eotret 5 2,051 Aug-09-2024, 07:19 AM
Last Post: Pedroski55
Bug Python 3.12 cannot import local python files as modules sunflowerdog 25 19,174 Jul-31-2024, 01:52 PM
Last Post: sunflowerdog
  Sending email using own smtp server robertkwild 11 6,191 Jul-05-2024, 12:59 AM
Last Post: AdamHensley
  (solved) Downnload images from a server and rename charled 13 3,146 Jun-20-2024, 08:16 AM
Last Post: charled
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 3,327 May-03-2024, 07:23 AM
Last Post: Pedroski55
  501 Server cannot accept argument anna17 0 935 Apr-11-2024, 01:08 AM
Last Post: anna17
Question [SOLVED] Tiny web server as standalone executable? Winfried 0 1,169 Feb-09-2024, 11:48 AM
Last Post: Winfried
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 1,042 Jan-26-2024, 07:02 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020