def _sync_datafs(host_type, path): data_host = api.env.data_hosts[0] src_path = os.path.join(path, 'var', 'filestorage', 'Data.fs') src_host_string = ':'.join([api.env.host_string, src_path]) target_path = os.path.join(api.env.base_data_path, api.env.project_name, 'data', 'current_prod') today = datetime.date.today().strftime('%Y-%m-%d') filename_test = 'Data.fs-%s-%s-%s-*.tgz' % (api.env.project_name, host_type, today) data_path = _get_data_path() result = _quiet_remote_ls(data_path, filename_test) existing_files = result.split() filename = 'Data.fs-%s-%s-%s-%02d.tgz' % (api.env.project_name, host_type, today, len(existing_files)+1) # Ensure the `current_prod` dir exists result = _quiet_remote_mkdir(target_path) with api.settings(host_string=data_host): _sshagent_run('rsync -z --inplace %s %s' % (src_host_string, target_path)) with api.cd(target_path): result = api.run('tar czf %s Data.fs' % filename) if result.succeeded: api.run('mv %s ..' % filename) else: api.run('rm -f %s' % filename)
def push_saved_data_to_qa(fname=None): """Push a saved data file to QA """ qa_path = os.path.join(api.env.base_qa_path, api.env.project_name, 'var') for data_host in api.env.data_hosts: with api.settings(host_string=data_host): if fname is None: fname = _get_data_fname('push') fpath = os.path.join(_get_data_path(), fname) for qa_host in api.env.qa_hosts: with api.settings(host_string=qa_host, warn_only=True): cmd = 'scp %s:%s %s' % (data_host, fpath, qa_path) _sshagent_run(cmd)