Replace rsync()
function in fablib.
This one requires some setup on the "live" server, but seems to work pretty well...
This commit is contained in:
parent
959a36f342
commit
a0869b1fc3
|
@ -185,34 +185,13 @@ def make_deploy(deploy_path, last_segment='deploy'):
|
||||||
return Deployer(deploy_path, last_segment)
|
return Deployer(deploy_path, last_segment)
|
||||||
|
|
||||||
|
|
||||||
def rsync(production_server, owner, *paths, **kwargs):
|
def rsync(host, *paths):
|
||||||
"""
|
"""
|
||||||
Perform a full rsync (production -> target host) of one or more file paths.
|
Runs rsync as root, for the given host and file paths.
|
||||||
"""
|
"""
|
||||||
if not paths:
|
|
||||||
raise ValueError("Must specify one or more paths to synchronize.")
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if not path.startswith('/'):
|
assert path.startswith('/')
|
||||||
raise ValueError("Only absolute paths are supported (got '{0}')".format(repr(path)))
|
path = path.rstrip('/')
|
||||||
|
cmd = 'SSH_AUTH_SOCK=$SSH_AUTH_SOCK rsync -aP --del root@{0}:{1}/ {1}'.format(host, path)
|
||||||
production_user = kwargs.get('production_user') or env.user
|
with settings(forward_agent=True):
|
||||||
ssh = "ssh -p {0}{1}".format(
|
sudo(cmd, shell=False)
|
||||||
env.port, " -i '{0}'".format(env.key_filename[0]) if env.key_filename else '')
|
|
||||||
if not os.path.exists('.rsync'):
|
|
||||||
os.mkdir('.rsync')
|
|
||||||
|
|
||||||
for path in paths:
|
|
||||||
path = path.strip('/')
|
|
||||||
local_path = '.rsync/{0}'.format(path)
|
|
||||||
|
|
||||||
# fetch files to local dir
|
|
||||||
if not os.path.exists(local_path):
|
|
||||||
os.makedirs(local_path)
|
|
||||||
local('rsync --archive --partial --progress --delete-during {0}@{1}:/{2}/* {3}/'.format(
|
|
||||||
production_user, production_server, path, local_path))
|
|
||||||
|
|
||||||
# push files to target host
|
|
||||||
sudo('chown --recursive {0}:{0} /{1}'.format(env.user, path))
|
|
||||||
local('rsync --archive --partial --progress --delete-during --rsh="{0}" {1}/* {2}@{3}:/{4}/'.format(
|
|
||||||
ssh, local_path, env.user, env.host, path))
|
|
||||||
sudo('chown --recursive {0} /{1}'.format(owner, path))
|
|
||||||
|
|
Loading…
Reference in a new issue