How do I automate a migration to another datacenter?

Linode Staff

You can do this using either the Linode API or the Linode CLI.

Using the Linode API

With the Linode API, you can create a request that looks like this:

curl -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
    -X POST -d '{
      "region": "$REGION"
    }' \
    https://api.linode.com/v4/linode/instances/"${LINODEID}"/migrate

Just replace $TOKEN with your Linode API Token, $REGION with the region you would like to migrate to (e.g. us-east), and "${LINODEID}" with your Linode's ID number. You can obtain a list of your Linode's ID numbers with this API call:

curl -H "Authorization: Bearer $TOKEN" \
    https://api.linode.com/v4/linode/instances

You can obtain a list of regions using this API call:

curl https://api.linode.com/v4/regions

The API returns data formatted as JSON, so I recommend using a tool like jq to make the responses a bit more readable. For example, to list all of the regions available in a neater format, you can use a call like this:

curl https://api.linode.com/v4/regions | jq | awk '/id/{print}'
      "id": "ap-west",
      "id": "ca-central",
      "id": "ap-southeast",
      "id": "us-central",
      "id": "us-west",
      "id": "us-southeast",
      "id": "us-east",
      "id": "eu-west",
      "id": "ap-south",
      "id": "eu-central",
      "id": "ap-northeast",


Using the Linode CLI

To do the same thing using the Linode CLI, you'll first need to have it installed. You can find instructions to install the Linode CLI onto your system here. Once installed and configured, you can obtain a list of your Linode's IDs with the following command:

linode-cli linodes list

To list the available regions, you can use this command:

linode-cli regions list

You can then initiate the migration with this command:

linode-cli linodes migrate --region $REGION $LINODEID


Getting an API Token

For either method, you'll need an API Token in order to authenticate to your Linode account. You can follow this guide to obtain an API Token.

0 Replies

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct