Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, mostraremos como fazer o backup de dados de uma máquina local para o Cloud Storage com o Cloud Tools for PowerShell. Ao contrário da maioria dos recursos, o Cloud Tools for PowerShell oferece duas maneiras de acessar os recursos do Google Cloud Storage: os cmdlets e um provedor do PowerShell.
O provedor permite acessar buckets do Storage e objetos como um sistema de arquivos com o uso dos comandos de sistema de arquivos que você já conhece. O provedor, no entanto, tem algumas limitações. Nem todos os nomes de objeto legais são convertidos em caminhos legais para o provedor. Você não pode usar o provedor para gerenciar ACLs. Para essas casos avançados, você pode usar os cmdlets.
Consulte a referência de cmdlets do Cloud Tools for PowerShell para saber mais sobre os cmdlets do Cloud Storage.
Como fazer upload de dados
Os dados no Cloud Storage são organizados em buckets. Use o seguinte procedimento para criar um novo bucket:
Cmdlets
Use o cmdlet New-GcsBucket para criar um novo bucket:
$bucket = "my-gcs-bucket"
New-GcsBucket $bucket
Provedor
Buckets são pastas na raiz da unidade gs:\. Criar um novo item nesse nível criará um novo bucket.
cd gs:\
$bucket = "my-gcs-bucket"
mkdir $bucket
Fazer o upload de arquivos para um bucket
Você pode enviar um único arquivo ou um diretório inteiro para seu bucket:
Cmdlets
Use New-GcsObject. Ele exige um bucket de destino e um nome de objeto como parâmetros. A origem do conteúdo do objeto do novo armazenamento depende dos parâmetros usados.
É possível fazer o upload do conteúdo de um arquivo local para o Cloud Storage usando o parâmetro -File e especificando um caminho de arquivo. Como alternativa, é possível passar o conteúdo do objeto como uma string por meio do pipeline do PowerShell ou usar o parâmetro -Value.
É possível fazer o upload de um diretório inteiro do disco local para o Cloud Storage usando o parâmetro -Folder e especificando o caminho da pasta. Se você não quiser que a pasta seja enviada diretamente para a raiz do bucket do Cloud Storage, use -ObjectNamePrefix para especificar um prefixo que será aplicado a todos os objetos enviados.
# Upload the folder LogFiles and its content to the root of the widget bucket.
New-GcsObject -Bucket "widget" -Folder "C:\inetpub\logs\LogFiles"
# Upload the folder LogFiles and its content to directory Test in the widget bucket.
New-GcsObject -Bucket "widget" -Folder "C:\inetpub\logs\LogFiles" -ObjectNamePrefix "Test"
Provedor
Use New-Item. Ele exige um caminho para o item que está sendo criado. Esse caminho pode ser absoluto ou relativo. O conteúdo do novo objeto do Storage pode ser especificado como uma string para o parâmetro -Value ou especificando um caminho de arquivo para o parâmetro -File.
New-Item gs:\my-gcs-bucket\new-object -File $file
O snippet a seguir faz o upload de um diretório inteiro do disco local para o Cloud Storage.
Você pode usar Get-ChildItem ou um dos aliases: dir, ls ou gci.
Você pode usar o parâmetro -Recurse para procurar em todas as pastas lógicas:
cd gs:\my-gcs-bucket
ls -Recurse
Ler dados
Para ler dados por meio do provedor, use o cmdlet Get-Content padrão.
Como alternativa, use o cmdlet Read-GcsObject.
Cmdlets
Para ler o conteúdo de um objeto do Cloud Storage, use o cmdlet Read-GcsObject. Por padrão, ele lê o conteúdo do objeto como uma string e o grava no canal do PowerShell. Especifique o parâmetro -OutFile para fazer o download do conteúdo do objeto para o disco local:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-01 UTC."],[],[],null,["# Backing up data to Cloud Storage\n\nThis page shows how to backup data from a local machine to\nCloud Storage using Cloud Tools for PowerShell. Unlike most resources,\nCloud Tools for PowerShell provides two ways to access Cloud Storage\nresources, the cmdlets and a PowerShell provider.\n\nThe provider allows you to access Storage buckets and objects like a file\nsystem, using the file system commands you are already familiar with. The\nprovider has some limitations, however. Not all legal object names convert to\nlegal provider paths. You can't use the provider to manage ACLs. For these\nadvanced cases, you can use the cmdlets.\nSee the [Cloud Tools for PowerShell cmdlet\nreference](http://googlecloudplatform.github.io/google-cloud-powershell/)\nto learn more about Cloud Storage cmdlets.\n\nUploading data\n--------------\n\nData in Cloud Storage is organized into buckets. Create a new bucket\nas follows: \n\n### Cmdlets\n\n\nUse the `New-GcsBucket` cmdlet\nto create a new bucket: \n\n```\n$bucket = \"my-gcs-bucket\"\nNew-GcsBucket $bucket\n```\n\n### Provider\n\n\nBuckets are folders at the root of the `gs:\\` drive. Creating a\nnew item at that level will create a new bucket. \n\n```\ncd gs:\\\n$bucket = \"my-gcs-bucket\"\nmkdir $bucket\n```\n\nUpload files to a bucket\n------------------------\n\nYou can upload a single file or an entire directory to your bucket: \n\n### Cmdlets\n\n\nUse `New-GcsObject`. This requires a destination bucket and an object name\nas parameters. Where the new Storage object's contents come from depends on\nwhich parameter set you use.\n\nYou can upload the contents of a local file to Cloud Storage by\nusing the `-File` parameter and specifying a file path. Alternatively, you\ncan pass the object's contents as a string via the PowerShell pipeline, or\nyou can use the `-Value` parameter.\n\nYou can upload an entire directory from the local disk to\nCloud Storage by using the `-Folder` parameter and specifying the\nfolder path. If you do not want the folder to be uploaded directly to the\nroot of the Cloud Storage bucket, use `-ObjectNamePrefix` to\nspecify a prefix that will be applied to every object uploaded. \n\n```\n# Upload the folder LogFiles and its content to the root of the widget bucket.\nNew-GcsObject -Bucket \"widget\" -Folder \"C:\\inetpub\\logs\\LogFiles\"\n\n# Upload the folder LogFiles and its content to directory Test in the widget bucket.\nNew-GcsObject -Bucket \"widget\" -Folder \"C:\\inetpub\\logs\\LogFiles\" -ObjectNamePrefix \"Test\"\n```\n\n### Provider\n\n\nUse `New-Item`. It requires a path to the item being created. This can be\nan absolute path or a relative path. The contents of the new Storage Object\ncan be specified either as a string to the `-Value` parameter or by\nspecifying a file path to the `-File` parameter. \n\n```\nNew-Item gs:\\my-gcs-bucket\\new-object -File $file\n```\n\nThe following snippet uploads an entire directory from the local disk to\nCloud Storage. \n\n```\ncd $folder\n$files = Get-ChildItem -Recurse\n$data = @()\nforeach ($file in $files) {\n $objectPath = $file | Resolve-Path -Relative\n $data += @{file = $file; objectPath = $objectPath}\n}\ncd gs:\\my-gcs-bucket\nforeach($element in $data) {\n Write-Host \"`t${$element.objectPath}\"\n New-Item $element.objectPath -File $element.file\n}\n```\n\nSearching data\n--------------\n\nYou can search data with cmdlets, or with the provider through the common file\nsearch cmdlets. \n\n### Cmdlets\n\n\nYou can search through a bucket's objects using `Get-GcsObject`. This can be\nuseful when combined with the `Out-GridView` cmdlet to visualize your data: \n\n```\nGet-GcsObject $bucket | Select Name, Size | Out-GridView\n```\n\n### Provider\n\n\nYou can use `Get-ChildItem` or one of its aliases: `dir`, `ls`, or `gci`.\nYou can use the `-Recurse` parameter to look within all of the logical\nfolders: \n\n```\ncd gs:\\my-gcs-bucket\nls -Recurse\n```\n\nReading data\n------------\n\nTo read data through the provider, use the standard `Get-Content` cmdlet.\nAlternatively, use the `Read-GcsObject` cmdlet. \n\n### Cmdlets\n\n\nTo read the contents of a Cloud Storage object, use the\n`Read-GcsObject` cmdlet. By default it reads the object's contents as a\nstring and writes it to the PowerShell pipeline. You can specify the\n`-OutFile` parameter to download the object's contents to the local disk\ninstead: \n\n```\nRead-GcsObject $bucket \"timestamp.txt\" | Write-Host\nRead-GcsObject $bucket \"logo.png\" `\n -OutFile \"$Env:UserProfile\\pictures\\logo.png\"\n```\n\n### Provider\n\n\nTo read the contents of a Cloud Storage object, use the `Get-Content`\ncmdlet, or one of its aliases: `cat`, `gc`, or `type`. \n\n```\ncd gs:\\my-gcs-bucket\ncat my-object-name\n```\n\nDeleting data\n-------------\n\nTo delete data through the provider, use the standard `Remove-Item` cmdlet.\nAlternatively, use the `Remove-GcsObject` cmdlet. \n\n### Cmdlets\n\n\nTo remove any data in Cloud Storage, use the `Remove-GcsObject`\ncmdlet: \n\n```\nGet-GcsObject $bucket | Remove-GcsObject\n```\n\n### Provider\n\n\nTo remove data in Cloud Storage, use the `Remove-Item` cmdlet, or\none of its aliases `del`, `rm`, `erase`: \n\n```\ncd gs:\\my-gcs-bucket\nrm my-object-name\n```"]]