# Migrate data

This page describes how to run a data migration that copies files from the
local machine to a persistent volume claim (PVC) in the target cluster.

This is an optional step.

## Customize your data migration configuration

When you [complete an analysis](https://docs.cloud.google.com/migrate/containers/docs/m2c-cli/create-a-migration-plan.md.txt),
Migrate to Containers CLI might create a data configuration file named `dataConfig.yaml`
in the specified analysis output directory. This indicates that to complete the
migration, you need to perform data migration.

You can also create this data configuration file manually for data migration,
and provide information about your target data volume or data claim.

Following is an example of a data configuration file:

```yaml
volumes:
- deploymentPvcName: my-pvc1
  existingPvc:
    name: my-pvc1
  folders:
  - /bin
  - /opt
- deploymentPvcName: my-pvc2
  newPvc:
   spec:
    accessModes:
    - ReadWriteOnce
    resources:
      requests:
        storage: 10G
  folders:
  - /bin
  - /opt
```

Where:

- `deploymentPvcName`: The PVC name to be used by Migrate to Containers
  in your deployed workload to access this volume.

  > [!NOTE]
  > **Note:** In case you've already [executed the migration](https://docs.cloud.google.com/migrate/containers/docs/m2c-cli/execute-the-migration-plan.md.txt), if you change this PVC name in the data configuration file, ensure that you make the same change in the other migration artifacts, or execute the migration again to update the generated artifacts.

- `existingPvc`:

  - `name`: Name of an existing persistent volume claim (PVC). Define if you want to migrate data volumes to an existing PVC.
- `newPvc`: Define if you want to migrate your data volumes to a new PVC. You
  can define your PVC using the standard PVC spec syntax.

  For more information about Kubernetes PVC spec, see the [Kubernetes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/)
  documentation.

  > [!NOTE]
  > **Note:** You can migrate a data volume to either an existing PVC or a new PVC. Therefore, you must only define one of the two parameters, `existingPvc` or `newPvc`, per volume.

- `folders`: the folder you want to migrate from the VM to PVC. These folders are
  copied to the PVC in the same path.

You can edit your data configuration file for several data migration use cases,
including:

- [Using an existing PVC](https://docs.cloud.google.com/migrate/containers/docs/m2c-cli/migrate-data.md.txt#use_an_existing_pvc)
- [Creating new volumes on your migrated VM](https://docs.cloud.google.com/migrate/containers/docs/m2c-cli/migrate-data.md.txt#create_new_data_volumes_on_your_migrated_vms)
- [Migrating multiple PVCs with multiple file paths](https://docs.cloud.google.com/migrate/containers/docs/m2c-cli/migrate-data.md.txt#migrate_multiple_pvcs_with_multiple_file_paths)

### Use an existing PVC

If you've already allocated the storage for your migrated data, and have a
PVC to store your data, you can migrate your data using an existing PVC.

Define an existing PVC in your data configuration file `dataConfig.yaml`
by passing your existing volume in the `existingPvc` field. In this case, your
data configuration file would look like this:

```yaml
volumes:
- deploymentPvcName: my-pvc
  existingPvc:
    name: my-pvc
    subpath: /subpath
  folders:
  - /bin
  - /opt
```

In the previous sample, the `existingPvc` entry can contain an optional
`subPath` to migrate data to the subpath of the PVC, as shown.

> [!NOTE]
> **Note:** The PVC has to be in the same namespace as the target namespace on the deployment cluster.

### Create new data volumes on your migrated VMs

If you've not allocated storage ahead of time, and you want your storage to be
created during the migration process, you can pass an empty `existingPvc` field
and specify the storage you would like to be created in the `newPvc` field:

```yaml
volumes:
- deploymentPvcName: my-pvc
  newPvc:
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 10G
  folders:
  - /bin
  - /opt
```

> [!NOTE]
> **Note:** If you don't want to worry about the specifics of your backing storage, use an empty string for the storage class, as shown in the preceding yaml.

### Migrate multiple PVCs with multiple file paths

You can specify the set of directories under the `folders` list field of each
entry in the `volume` list for each PVC listed in your data configuration file
`dataConfig.yaml`:

```yaml
volumes:
- deploymentPvcName: my-pvc1
  existingPvc:
    name: my-pvc1
  folders:
  - /bin
  - /opt
- deploymentPvcName: my-pvc2
  newPvc:
   spec:
    accessModes:
    - ReadWriteOnce
    resources:
     requests:
       storage: 10G
  folders:
  - /bin
  - /opt
```

The paths you list under `folders` in the data configuration file are copied to
the same paths in the target PVCs.

## Execute the data migration

After you've customized your data configuration file `dataConfig.yaml`, to
migrate the data volumes to a PVC in the target cluster, run the following
command:

    ./m2c migrate-data  -i ANALYSIS_OUTPUT_PATH -n NAMESPACE

Replace the following:

- <var translate="no">ANALYSIS_OUTPUT_PATH</var>: the path where you saved the [analysis
  output](https://docs.cloud.google.com/migrate/containers/docs/m2c-cli/create-a-migration-plan) that contains the file `dataConfig.yaml`
- <var translate="no">NAMESPACE</var>: the target Kubernetes cluster namespace of the deployed network

## What's next

- Learn how to [clean up your local machine](https://docs.cloud.google.com/migrate/containers/docs/m2c-cli/clean-up.md.txt).