问题
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
The command runs and completes:
data.csv 100% 74KB 73.9KB/s 00:00
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?
回答1:
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).
Not-so-short answer
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
# [...]
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:
- Use current
$USER
if it's valid under GCE-specific constraints—namely, ASCII characters containing no whitespaces. - Otherwise, extract the username from the
gcloud
account currently logged in (you can check which one it is by runninggcloud 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
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.
来源:https://stackoverflow.com/questions/38688880/gcloud-compute-copy-files-succeeds-but-no-files-appear