Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menunjukkan cara mencadangkan data dari komputer lokal ke
Cloud Storage menggunakan Cloud Tools for PowerShell. Tidak seperti sebagian besar resource,
Cloud Tools for PowerShell menyediakan dua cara untuk mengakses resource Cloud Storage, yaitu cmdlet dan penyedia PowerShell.
Penyedia ini memungkinkan Anda mengakses bucket dan objek Storage seperti sistem file, menggunakan perintah sistem file yang sudah Anda pahami. Namun, penyedia ini memiliki beberapa batasan. Tidak semua nama objek hukum dikonversi ke
jalur penyedia hukum. Anda tidak dapat menggunakan penyedia untuk mengelola ACL. Untuk kasus
lanjutan ini, Anda dapat menggunakan cmdlet.
Lihat referensi cmdlet Cloud Tools for PowerShell untuk mempelajari cmdlet Cloud Storage lebih lanjut.
Mengupload data
Data di Cloud Storage diatur ke dalam bucket. Buat bucket baru
sebagai berikut:
Cmdlet
Gunakan cmdlet New-GcsBucket
untuk membuat bucket baru:
$bucket = "my-gcs-bucket"
New-GcsBucket $bucket
Penyedia
Bucket adalah folder di root drive gs:\. Membuat item baru di tingkat tersebut akan membuat bucket baru.
cd gs:\
$bucket = "my-gcs-bucket"
mkdir $bucket
Mengupload file ke bucket
Anda dapat mengupload satu file atau seluruh direktori ke bucket:
Cmdlet
Menggunakan New-GcsObject. Tindakan ini memerlukan bucket tujuan dan nama objek sebagai parameter. Sumber konten objek Storage baru bergantung pada
kumpulan parameter yang Anda gunakan.
Anda dapat mengupload konten file lokal ke Cloud Storage dengan menggunakan parameter -File dan menentukan jalur file. Atau, Anda
dapat meneruskan konten objek sebagai string melalui pipeline PowerShell, atau
Anda dapat menggunakan parameter -Value.
Anda dapat mengupload seluruh direktori dari disk lokal ke Cloud Storage menggunakan parameter -Folder dan menentukan jalur folder. Jika Anda tidak ingin folder diupload langsung ke
root bucket Cloud Storage, gunakan -ObjectNamePrefix untuk
menentukan awalan yang akan diterapkan ke setiap objek yang diupload.
# 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"
Penyedia
Menggunakan New-Item. Ini memerlukan jalur ke item yang sedang dibuat. Jalur ini dapat berupa
jalur absolut atau jalur relatif. Konten Objek Penyimpanan baru
dapat ditentukan sebagai string ke parameter -Value atau dengan
menentukan jalur file ke parameter -File.
New-Item gs:\my-gcs-bucket\new-object -File $file
Cuplikan berikut mengupload seluruh direktori dari disk lokal ke Cloud Storage.
Anda dapat menelusuri data dengan cmdlet, atau dengan penyedia melalui cmdlet penelusuran file
umum.
Cmdlet
Anda dapat menelusuri objek bucket menggunakan Get-GcsObject. Hal ini dapat
berguna jika digabungkan dengan cmdlet Out-GridView untuk memvisualisasikan data Anda:
Anda dapat menggunakan Get-ChildItem atau salah satu aliasnya: dir, ls, atau gci.
Anda dapat menggunakan parameter -Recurse untuk melihat dalam semua folder
logis:
cd gs:\my-gcs-bucket
ls -Recurse
Membaca data
Untuk membaca data melalui penyedia, gunakan cmdlet Get-Content standar.
Atau, gunakan cmdlet Read-GcsObject.
Cmdlet
Untuk membaca konten objek Cloud Storage, gunakan cmdlet Read-GcsObject. Secara default, fungsi ini membaca konten objek sebagai
string dan menulisnya ke pipeline PowerShell. Anda dapat menentukan
parameter -OutFile untuk mendownload konten objek ke disk lokal
sebagai gantinya:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-17 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```"]]