You can use cross-project data access to migrate data between MaxCompute projects in different regions, either under the same Alibaba Cloud account or across different accounts.
Limitations
This solution supports data migration for MaxCompute projects only between regions in mainland China.
Migration for projects under the same account
Migrate table data from a source project (projectA) to a destination project (projectB) when both projects are owned by the same Alibaba Cloud account.
As the Alibaba Cloud account owner, you can create the destination table directly in the destination project:
Create a table and copy data
-- Switch to the destination project, projectB. use projectB; set odps.namespace.schema=false; -- Create a new table based on the source table in projectA and copy the data. create table [if not exists] <table_name> [lifecycle <days>] as select * from projectA.<table_name>;Create a table first, then copy data
-- Switch to the destination project, projectB. use projectB; set odps.namespace.schema=false; -- Create a new table with the same schema as the source table without copying data. create table [if not exists] <table_name> like projectA.<table_name> [lifecycle <days>]; -- Write data from the source table to the new table in the destination project. insert {into|overwrite} table <table_name> [partition (<pt_spec>)] [(<col_name> [,<col_name> ...)]] select * from projectA.<table_name> [zorder by <zcol_name> [, <zcol_name> ...]];For more information, see Table operations.
If you are using a RAM user or RAM role, ensure that the source project is in a Normal state. You must have the
SELECTpermission on the source table, and theCreateInstanceandCreateTablepermissions on the destination project. You can obtain theSELECTpermission on the source table in one of two ways:Method 1: After you add the RAM account to data source project A (for instructions, see User planning and management) and grant it permissions on the required resources (for more information, see Manage user permissions by using commands), the RAM account can access the data source tables.
Method 2: Use package-based authorization for cross-project access. The owner of the Alibaba Cloud account packages the resources in the source project (projectA) into a package and authorizes the destination project (projectB) to install it. After projectB installs the package, grant the read permission on the package to the user in projectB. For detailed steps, see Cross-project resource access based on packages.
Migration for projects under different accounts
Step 1: Grant read permission on source data
Access projects across different Alibaba Cloud accounts in one of two ways:
Method 1: Add the owner of the destination project (projectB), which is Alibaba Cloud account B (ALIYUN$projectB_owner@aliyunid.com), as a user to the source project (projectA). Then, grant the necessary resource permissions to this user. For more information, see User planning and management and Manage user permissions by using commands.
--Enter the source project projectA. use projectA; --Add the Alibaba Cloud account of the destination project (projectB) owner (projectB_owner@aliyunid.com) to the source project (projectA). add user ALIYUN$projectB_owner@aliyunid.com; --Grant the CreateTable and CreateInstacne permissions on the source project projectA to the user ALIYUN$projectB_owner@aliyunid.com. grant CreateTable,CreateInstance on project projectA to user ALIYUN$projectB_owner@aliyunid.com; --Grant the Select permission on the source table to the user ALIYUN$projectB_owner@aliyunid.com. grant Select on table <tablename> to user ALIYUN$projectB_owner@aliyunid.com;Method 2: Use package-based authorization. The owner of the source project (Account A) creates a package from the resources in projectA. Account A then authorizes the destination project, projectB (owned by Account B), to install the package. After projectB installs the package, Account B can access the resources within it. For detailed steps, see Cross-project resource access based on packages.
Step 2: Migrate the data
As the Alibaba Cloud account owner, you can create the destination table directly in the destination project:
Create a table and copy data
-- Switch to the destination project, projectB.
use projectB;
set odps.namespace.schema=false;
-- Create a new table based on the source table in projectA and copy the data.
create table [if not exists] <table_name> [lifecycle <days>] as select * from projectA.<table_name>; Create a table first, then copy data
-- Switch to the destination project, projectB.
use projectB;
set odps.namespace.schema=false;
-- Create a new table with the same schema as the source table without copying data.
create table [if not exists] <table_name> like projectA.<table_name> [lifecycle <days>];
-- Write data from the source table to the new table in the destination project.
insert {into|overwrite} table <table_name> [partition (<pt_spec>)] [(<col_name> [,<col_name> ...)]]
select * from projectA.<table_name> [zorder by <zcol_name> [, <zcol_name> ...]];For more information, see Table operations.
To ensure data security, remove the destination project owner's Alibaba Cloud account from the source project after the data migration is complete. For more information, see Remove an Alibaba Cloud account user (project-level).