fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] Rsync_project in 1.5.1


From: Carl E. Ma
Subject: Re: [Fab-user] Rsync_project in 1.5.1
Date: Mon, 3 Dec 2012 08:26:26 -0800 (PST)

Hi Jeff, 

Thanks for your reply! Here is fab script. It reads in hostname/ssh port/log type(tomcat or apache)/logfile path from logs.conf, which has format like following. If uncomment the rsync_project line, script will report host error.  We can't use get method as it doesn't do differential copy.
===
host1;22: tomcat;/opt/tomcat/logs/app.log,apache;/var/log/httpd/access_log,tomcat;/opt/tomcat/logs/catalina.out
host2;2022: tomcat;/opt/tomcat/logs/app.log,apache;/var/log/httpd/access_log,tomcat;/opt/tomcat/logs/catalina.out
===

#!/usr/bin/python
from fabric.api import *
from fabric.api import env, run
from fabric.tasks import execute
from fabric.colors import *
from fabric.operations import *
from fabric.contrib.project import rsync_project
import datetime as dt
import yaml
import os

def remoteRun():
    print "ENV %s" %(env.hosts)
    out = run('uname -n')

def SyncLog(To,From,Port):
  # remoteRun()
#   print To + '----' + From
   print key+":"+Port
   SSHOptions='-e "ssh -p ' + Port + '"'
  # rsync_project(To,From)
   os.system("rsync -a --update --delete --delete-after " + SSHOptions + " userXXX@" + key + ":" + From + " " + To)

configs  = yaml.load(open('logs.conf'))
for Host,value in configs.iteritems() :

#   print env.host_string
   key,Port=Host.split(';')
   env.host_string = key
   for j in value.split(','):
#      print  'host' + key + ' has value ' + j
      Dir,LogName=j.split(';')
      PathName = "/logs"+"/"+key+"/"+Dir
#      print Dir+" and "+LogName 
      if not os.path.isdir(PathName):
         print PathName + " does not exist! "
         os.makedirs(PathName)
      SyncLog(PathName,LogName,Port)
#      remoteRun()

Thanks,

carl



From: Jeff Forcier <address@hidden>
To: Carl E. Ma <address@hidden>
Cc: "address@hidden" <address@hidden>
Sent: Saturday, December 1, 2012 6:33:28 PM
Subject: Re: [Fab-user] Rsync_project in 1.5.1

Hi Carl,

On Tue, Nov 27, 2012 at 1:19 PM, Carl E. Ma <address@hidden> wrote:
> Hello,
>
> Problem I experienced is rsync_project does not take value from host_string variable and keeps reporting no host defined. I can use os.system() to run rsync, but just wonder what I missed when use rsync_project.

Something may be slightly off in your code -- rsync_project definitely
makes use of env.host_string:

    https://github.com/fabric/fabric/blob/master/fabric/contrib/project.py#L101

If you are able to share a sample of your code & the output from when
you run it, that might help us figure out what's up.

I'll also mention that get() is capable of grabbing files recursively
(and can also use glob syntax), so depending on your specifics, that
might be worth exploring over rsync.

Best,
Jeff


--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]