gcloudcompute复制文件成功,但没有文件出现 [英] gcloud compute copy-files succeeds but no files appear

查看:69
本文介绍了gcloudcompute复制文件成功,但没有文件出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将数据从本地计算机复制到计算引擎实例:

I am copying data from my local machine to a compute engine instance:

gcloud compute copy-files /Users/me/project/data.csv instance-name:~/project

命令运行并完成:

data.csv 100%   74KB  73.9KB/s   00:00

但是,我无法在计算引擎实例的任何位置找到它.在~/project文件夹中不可见.是无声地失败还是我找错地方了?

However, I cannot find it anywhere on my compute engine instance. It is not visible in the ~/project folder. Is it failing silently or am I looking in the wrong place?

推荐答案

简短答案

很可能您正在寻找错误的$HOME.确保你在找 在您要复制的同一用户的主目录中(它将是 (如果以前不存在,则在远程主机上创建).

Short answer

Most likely, you're looking into the wrong $HOME. Make sure you're looking in the home directory of the same user you're copying from (it will be created on the remote host if it didn't previously exist).

如果在调用copy-files时未指定任何远程用户,则gcloud 将尝试找出要登录的用户.您可以在以下情况下看到此效果 您可以查看gcloud源代码:

If you don't specify any remote user when invoking copy-files, then gcloud will try to figure out which user to login with. You can see this in action if you take a look into gcloud source code:

# $CLOUD_SDK_ROOT/lib/surface/compute/copy_files.py

# [...]

user_host, file_path = arg.split(':', 1)
user_host_parts = user_host.split('@', 1)
if len(user_host_parts) == 1:
    user = ssh_utils.GetDefaultSshUsername(warn_on_account_user=True)
    instance = user_host_parts[0]
else:
    user, instance = user_host_parts

# [...]

在您的情况下,由于您未指定任何用户,因此GetDefaultSshUsername() 将被调用,其任务是找到一个有效的SSH用户名以 使用.为此,它将选择符合以下条件的第一个选项 顺序:

In your case, since you didn't specify any user, GetDefaultSshUsername() will be called, and its mission is to find a valid SSH username to use. To do so, it will pick the first option that qualifies in the following order:

  1. 如果当前$USER在GCE特定的约束下有效,请使用它,即, ASCII字符,不包含空格.
  2. 否则,从当前登录的gcloud帐户中提取用户名 进入(您可以通过运行gcloud auth list检查它是哪一个)
  1. Use current $USER if it's valid under GCE-specific constraints—namely, ASCII characters containing no whitespaces.
  2. Otherwise, extract the username from the gcloud account currently logged in (you can check which one it is by running gcloud auth list)

再一次,源代码告诉我们最终的真理:

Once again, source code tells us the ultimate truth:

# $CLOUD_SDK_ROOT/lib/googlecloudsdk/api_lib/compute/ssh_utils.py

def GetDefaultSshUsername(warn_on_account_user=False):
    # [...]
    user = getpass.getuser()
    if not _IsValidSshUsername(user):
        full_account = properties.VALUES.core.account.Get(required=True)
        account_user = gaia_utils.MapGaiaEmailToDefaultAccountName(full_account)
        if warn_on_account_user:
            log.warn('Invalid characters in local username [{0}]. '
                     'Using username corresponding to active account: [{1}]'.format(user, account_user))
        user = account_user
    return user

所以,现在我们知道了大致选择远程用户名的过程 可行,我的推测是您使用复制了data.csv文件 与后来检查远程实例的用户不同的用户 如果文件在那,因为默认情况下它们会落在他们的文件上 相应的和不同的$HOME目录.

So, now that we know how the process of picking a remote username roughly works, my educated guess is that you copied your data.csv file using a different user than the one that was later on checking on the remote instance if the file was there, since by default they'll land on their respective –and different– $HOME directory.

这篇关于gcloudcompute复制文件成功,但没有文件出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆