HomeComputeInstancesAPI/CLI
Migrating Instances

Update content

Migrating Instances with the API

Published on 26 May 2021

It is possible to automate the migration between two Instances by using the API.

To migrate an Instance via the API, the instance ID, a valid API Key and the users organization key are required.

Security & Identity (IAM):

You may need certain IAM permissions to carry out some actions described on this page. This means:

  • you are the Owner of the Scaleway Organization in which the actions will be carried out, or
  • you are an IAM user of the Organization, with a policy granting you the necessary permission sets
  1. Start by making a backup of your Instance. Replace <REGION> with the region of your server. This value can be fr-par-1 for Instances located in Paris, for example.

    Request:

    curl -H "X-Auth-Token: $SECRET_KEY" https://api.scaleway.com/instance/v1/zones/<REGION>/servers/<INSTANCE_ID>/action -d '{"action" : "backup"}' -H "Content-Type: application/json"

    Return:

    {
    "task": {
    "description": "server_backup",
    "href_from": "/servers/13d0c8d4-cc56-4f8b-b15c-ea25e8dbe989/action",
    "href_result": "/images/88996119-edb9-4283-8a6e-f9b98999bc19",
    "id": "b209f550-c8e1-4378-83e7-961dd834eb9c",
    "progress": 0,
    "started_at": "2019-05-14T13:14:01.573950+00:00",
    "status": "pending",
    "terminated_at": null
    }

    The ID of the image is indicated in the line "href_result": "/images/88996119-edb9-4283-8a6e-f9b98999bc19" Take a note of the ID, as it will be required in the next step.

  2. Create the new instance based on the backup created previously. To do so, use the image ID from the "href_result".

    Request:

    curl https://api.scaleway.com/instance/v1/zones/<REGION>/servers \
    -H "X-Auth-Token: $SECRET_KEY" \
    -H "Content-Type: application/json" \
    -d '{ \
    "name": "<NEW_INSTANCE_NAME>",
    "image": "88996119-edb9-4283-8a6e-f9b98999bc19",
    "commercial_type": "GP1-S",
    "tags": ["migration"],
    "organization": "<ORGANIZATION_ID>"}'

    Return:

    {
    "server": {
    "allowed_actions": [
    "poweron",
    "backup"
    ],
    "arch": "x86_64",
    "boot_type": "local",
    "bootscript": {
    "architecture": "x86_64",
    "bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16",
    "default": false,
    "dtb": "",
    "id": "54ee2857-8ffb-4323-abba-964f55fea4a2",
    "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.14.6.gz",
    "kernel": "http://169.254.42.24/kernel/x86_64-mainline-lts-4.9-4.9.93-rev1/vmlinuz-4.9.93",
    "organization": "11111111-1111-4111-8111-111111111111",
    "public": true,
    "title": "x86_64 mainline 4.9.93 rev1"
    },
    "commercial_type": "GP1-S",
    "compute_cluster": null,
    "creation_date": "2019-05-14T13:35:06.734740+00:00",
    "dynamic_ip_required": true,
    "enable_ipv6": false,
    "extra_networks": [],
    "hostname": "new-server",
    "id": "c7348333-bd5d-403f-ba54-9b4b398c8c8d",
    "image": {
    "arch": "x86_64",
    "creation_date": "2019-05-14T13:14:01.369030+00:00",
    "default_bootscript": {
    "architecture": "x86_64",
    "bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16",
    "default": false,
    "dtb": "",
    "id": "54ee2857-8ffb-4323-abba-964f55fea4a2",
    "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.14.6.gz",
    "kernel": "http://169.254.42.24/kernel/x86_64-mainline-lts-4.9-4.9.93-rev1/vmlinuz-4.9.93",
    "organization": "11111111-1111-4111-8111-111111111111",
    "public": true,
    "title": "x86_64 mainline 4.9.93 rev1"
    },
    "extra_volumes": {},
    "from_server": "13d0c8d4-cc56-4f8b-b15c-ea25e8dbe989",
    "id": "88996119-edb9-4283-8a6e-f9b98999bc19",
    "modification_date": "2019-05-14T13:14:01.369030+00:00",
    "name": "image_testserver_2019-05-14_13-14",
    "organization": "11111111-1111-4111-8111-111111111111",
    "public": false,
    "root_volume": {
    "id": "b57c43a6-dcac-4b4e-b7c2-564a9fd5e29c",
    "name": "snapshot_testserver_0_2019-05-14_13-14",
    "size": 20000000000,
    "volume_type": "l_ssd"
    },
    "state": "available"
    },
    "ipv6": null,
    "location": null,
    "maintenances": [],
    "modification_date": "2019-05-14T13:35:07.608285+00:00",
    "name": "new_server",
    "organization": "11111111-1111-4111-8111-111111111111",
    "private_ip": null,
    "protected": false,
    "public_ip": null,
    "security_group": {
    "id": "13e12ca4-1dfc-4460-a141-2bf63045a1c5",
    "name": "Default security group"
    },
    "state": "stopped",
    "state_detail": "",
    "tags": [
    "migration"
    ],
    "volumes": {
    "0": {
    "creation_date": "2019-05-14T13:35:06.734740+00:00",
    "export_uri": null,
    "id": "304a5478-bea4-49d1-b382-757d3c04adb3",
    "modification_date": "2019-05-14T13:35:07.422687+00:00",
    "name": "snapshot_testserver_0_2019-05-14_13-14",
    "organization": "11111111-1111-4111-8111-111111111111",
    "server": {
    "id": "c7348333-bd5d-403f-ba54-9b4b398c8c8d",
    "name": "new_server"
    },
    "size": 300000000000,
    "state": "available",
    "volume_type": "l_ssd"
    }
    }
    }
    }
  3. The new instance is available in the account now, but currently powered off. Power it up by launching an action on the instance:

    Request:

    curl -H "X-Auth-Token: $SECRET_KEY" https://api.scaleway.com/instance/v1/zones/<REGION>/servers/<SERVER_ID>/action \
    -d '{"action":"poweron"}' -H "Content-Type: application/json"

    Response:

    {
    "task": {
    "description": "server_batch_poweron",
    "href_from": "/servers/c7348333-bd5d-403f-ba54-9b4b398c8c8d/action",
    "href_result": "/servers/c7348333-bd5d-403f-ba54-9b4b398c8c8d",
    "id": "882af4d9-bca3-4005-880e-981fbcaa3343",
    "progress": 0,
    "started_at": "2019-05-14T14:05:12.154138+00:00",
    "status": "pending",
    "terminated_at": null
    }
    }
  4. In a final step update the flexible IP of the instance so it will point to the new instance:

    Request:

    curl --header "X-Auth-Token: $SECRET_KEY" --header 'Content-Type: application/json' --data '{"server" : "<SERVER_ID>"}' -X PATCH https://api.scaleway.com/instance/v1/zones/<REGION>/ips/<IP_ID>

    Response:

    {
    "ip": {
    "address": "51.15.74.234",
    "id": "3b0e7af9-3fe8-4cad-9919-0eaaa6966d8f",
    "organization": "11111111-1111-4111-8111-111111111111",
    "reverse": null,
    "server": {
    "id": "c7348333-bd5d-403f-ba54-9b4b398c8c8d",
    "name": "new_server"
    }
    }

    The new instance will now be reachable on the usual IP address.

  5. Optionally, delete the old instance in case it is no longer used:

    Request:

    curl --header "X-Auth-Token: $SECRET_KEY" -X DELETE https://api.scaleway.com/instance/v1/zones/<REGION>/servers/<SERVER_ID>

    Response: Empty (204)

    For more information on using the API, refer to the complete API documentation.