( projectId = 'my-project', sourceAgentPoolName = '', rootDirectory = '', gcsSinkBucket = '' )
| 17 | 'use strict'; |
| 18 | |
| 19 | async function main( |
| 20 | projectId = 'my-project', |
| 21 | sourceAgentPoolName = '', |
| 22 | rootDirectory = '', |
| 23 | gcsSinkBucket = '' |
| 24 | ) { |
| 25 | // [START storagetransfer_transfer_from_posix] |
| 26 | |
| 27 | // Imports the Google Cloud client library |
| 28 | const { |
| 29 | StorageTransferServiceClient, |
| 30 | } = require('@google-cloud/storage-transfer'); |
| 31 | |
| 32 | /** |
| 33 | * TODO(developer): Uncomment the following lines before running the sample. |
| 34 | */ |
| 35 | // Your project id |
| 36 | // const projectId = 'my-project' |
| 37 | |
| 38 | // The agent pool associated with the POSIX data source. Defaults to the default agent |
| 39 | // const sourceAgentPoolName = 'projects/my-project/agentPools/transfer_service_default' |
| 40 | |
| 41 | // The root directory path on the source filesystem |
| 42 | // const rootDirectory = '/directory/to/transfer/source' |
| 43 | |
| 44 | // The ID of the GCS bucket to transfer data to |
| 45 | // const gcsSinkBucket = 'my-sink-bucket' |
| 46 | |
| 47 | // Creates a client |
| 48 | const client = new StorageTransferServiceClient(); |
| 49 | |
| 50 | /** |
| 51 | * Creates a request to transfer from the local file system to the sink bucket |
| 52 | */ |
| 53 | async function transferDirectory() { |
| 54 | const createRequest = { |
| 55 | transferJob: { |
| 56 | projectId, |
| 57 | transferSpec: { |
| 58 | sourceAgentPoolName, |
| 59 | posixDataSource: { |
| 60 | rootDirectory, |
| 61 | }, |
| 62 | gcsDataSink: {bucketName: gcsSinkBucket}, |
| 63 | }, |
| 64 | status: 'ENABLED', |
| 65 | }, |
| 66 | }; |
| 67 | |
| 68 | // Runs the request and creates the job |
| 69 | const [transferJob] = await client.createTransferJob(createRequest); |
| 70 | |
| 71 | const runRequest = { |
| 72 | jobName: transferJob.name, |
| 73 | projectId: projectId, |
| 74 | }; |
| 75 | |
| 76 | await client.runTransferJob(runRequest); |
no test coverage detected