{"id":4772,"date":"2022-08-30T08:00:09","date_gmt":"2022-08-30T15:00:09","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cosmosdb\/?p=4772"},"modified":"2022-08-30T08:01:28","modified_gmt":"2022-08-30T15:01:28","slug":"copy-container-preview","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cosmosdb\/copy-container-preview\/","title":{"rendered":"Intra-account container copy jobs for Core (SQL) and Cassandra API accounts (Preview)"},"content":{"rendered":"<p>Announcing the preview for <a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/intra-account-container-copy\" target=\"_blank\" rel=\"noopener\">Intra-account container copy jobs<\/a>. This functionality helps create offline copies of containers for Azure Cosmos DB for both Core (SQL) API and Cassandra API using Azure CLI.<\/p>\n<h2>When to use<\/h2>\n<p>The container copy feature for Azure Cosmos DB is helpful for the following scenarios:<\/p>\n<ul>\n<li>Copy all items from one container to another.<\/li>\n<li>Change the\u00a0<a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/set-throughput#set-throughput-on-a-database-and-a-container\" target=\"_blank\" rel=\"noopener\">granularity at which throughput is provisioned &#8211; from database to container<\/a>\u00a0and vice-versa.<\/li>\n<li>Change the\u00a0<a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/partitioning-overview#choose-partitionkey\" target=\"_blank\" rel=\"noopener\">partition key<\/a>\u00a0of a container.<\/li>\n<li>Update the\u00a0<a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/unique-keys\" target=\"_blank\" rel=\"noopener\">unique keys<\/a>\u00a0for a container.<\/li>\n<li>Rename a container\/database.<\/li>\n<li>Use features that require a new container to be created.<\/li>\n<\/ul>\n<h2>Steps to use intra-account container copy<\/h2>\n<p>Here are the steps to use intra-account container copy with an example.<\/p>\n<p>In this example we will copy data from \u2018<em>container1\u2019 to <\/em>\u2018<em>container2<\/em>\u2019 for a Core (SQL) API account named,<em> \u2018contoso-container-copydemo<\/em><em>\u2019. <\/em>In this scenario we&#8217;re migrating from a contain in a database with shared database throughput \u2018<em>db1\u2019<\/em> to a container with dedicated throughput in \u2018<em>db2\u2019.<\/em><\/p>\n<ol>\n<li>Start by creating the destination container <em>\u2018container2\u2019<\/em> with the right settings. In this case, the destination container will have dedicated throughput of 20k RU\/s.<\/li>\n<\/ol>\n<p style=\"padding-left: 40px;\"><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/Picture1.png\"><img decoding=\"async\" class=\"alignnone size-large wp-image-4773\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/Picture1-1024x635.png\" alt=\"1. Start by creating the destination container \u2018container2\u2019 with the right settings. In this case, we are creating the destination container with a dedicated throughput of 20k RUs.\" width=\"640\" height=\"397\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/Picture1-1024x635.png 1024w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/Picture1-300x186.png 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/Picture1-768x476.png 768w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/Picture1-1536x952.png 1536w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/Picture1.png 1605w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-size: 12pt;\"><strong><div class=\"alert alert-info\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Important!<\/strong><\/p>Container copy jobs do not create the destination containers automatically. It is necessary to create the container in advance.<\/div><\/strong>\u00a0<\/span><\/p>\n<ol start=\"2\">\n<li>Stop any ongoing operations on the source container <em>\u2018container1\u2019<\/em>. This is necessary since we do not support online container copy right now. Updates or deletes executed on the source container after the copy job has started may not be captured and copied to the target container. Hence, continuing to perform operations on the source container while the container job is in progress may result in additional or missing data on the target container.<\/li>\n<\/ol>\n<ol start=\"3\">\n<li>Create the container copy job from Cloud Shell Bash. (If you have not used Cloud Shell before, <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cloud-shell\/quickstart#start-cloud-shell\" target=\"_blank\" rel=\"noopener\">here\u2019s how you open it.<\/a>)<\/li>\n<\/ol>\n<p style=\"padding-left: 40px;\">Alternatively, you may run the copy container jobs from your local machine with Azure CLI installed.<\/p>\n<p style=\"padding-left: 40px;\">a. First set the shell variables that the container copy command will use:<code><\/code><code><\/code><\/p>\n<pre class=\"prettyprint\" style=\"padding-left: 80px;\">rg=contoso-container-copydemo\r\ncosmosdbaccountname=contoso-container-copy-sqldemo\r\ncopyJobName=copy\r\nsourceDb=db1\r\nsourceContainer=container1\r\ndestinationDb=db2\r\ndestinationContainer=container2<\/pre>\n<p style=\"padding-left: 40px;\">b. Post that, run the command to create the container copy job:<\/p>\n<pre class=\"prettyprint\" style=\"padding-left: 80px;\">az cosmosdb dts copy -g $rg --account-name $cosmosdbaccountname --job-name $copyJobName \\\r\n--source-sql-container database=$sourceDb container=$sourceContainer \\\r\n--dest-sql-container database=$destinationDb container=$destinationContainer<code><\/code><\/pre>\n<p style=\"padding-left: 40px;\">You will see a response like below, indicating that the job has been queued and is in \u2018<em style=\"font-size: 1rem;\">Pending\u2019<\/em><span style=\"font-size: 1rem;\"> state.<\/span><\/p>\n<p style=\"padding-left: 40px;\"><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-job-queued-cli.png\"><img decoding=\"async\" class=\"aligncenter wp-image-4783 size-large\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-job-queued-cli-1024x323.png\" alt=\"Image containercopy job queued cli\" width=\"640\" height=\"202\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-job-queued-cli-1024x323.png 1024w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-job-queued-cli-300x95.png 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-job-queued-cli-768x242.png 768w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-job-queued-cli-1536x484.png 1536w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-job-queued-cli-2048x646.png 2048w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"font-size: 1rem;\">The equivalent command for creating a container copy job within a Cassandra API account would be:<\/span><\/p>\n<pre class=\"prettyprint\" style=\"padding-left: 80px;\">az cosmosdb dts copy -g $rg --account-name $cosmosdbaccountname --job-name $copyJobName \\\r\n--source-cassandra-table keyspace=$sourceKeySpace table=$sourceTable \\\r\n--dest-cassandra-table keyspace=$destinationKeySpace table=$destinationTable<\/pre>\n<ol start=\"4\">\n<li>Monitor the progress of the job and wait until the job status shows up as \u2018Completed\u2019. During the job you can monitor the number of items copied by watching <span style=\"font-family: terminal, monaco, monospace;\">processedCount<\/span> and the total items to be copied for the job as <span style=\"font-family: terminal, monaco, monospace;\">totalCount<\/span> using the command below.<\/li>\n<\/ol>\n<pre class=\"prettyprint\" style=\"padding-left: 80px;\">az cosmosdb dts show -g $rg --account-name $cosmosdbaccountname --job-name $copyJobName<\/pre>\n<p style=\"padding-left: 40px;\"><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-track-cli.png\"><img decoding=\"async\" class=\"aligncenter wp-image-4784 size-large\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-track-cli-1024x299.png\" alt=\"Image containercopy track cli\" width=\"640\" height=\"187\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-track-cli-1024x299.png 1024w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-track-cli-300x88.png 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-track-cli-768x224.png 768w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-track-cli-1536x448.png 1536w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2022\/08\/containercopy-track-cli-2048x598.png 2048w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<ol start=\"5\">\n<li>The last step would be to resume the operations by pointing the application or client to the source or destination container as intended.<\/li>\n<\/ol>\n<p style=\"padding-left: 40px;\">In this case, we would continue using the destination container \u2018<em>container2\u2019<\/em>.<\/p>\n<h2>Next Steps<\/h2>\n<p>To get started using container copy jobs, register for the <em>&#8220;Intra-account offline container copy (Cassandra &amp; SQL)&#8221;<\/em> preview from the <a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/access-previews\" target=\"_blank\" rel=\"noopener\">&#8216;Preview Features\u2019 list in the Azure portal<\/a>.<\/p>\n<p>You can <a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/intra-account-container-copy\" target=\"_blank\" rel=\"noopener\">learn more about intra-account container copy<\/a> as well as refer <a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/how-to-container-copy\" target=\"_blank\" rel=\"noopener\">how to create and monitor container copy jobs<\/a> for your Azure Cosmos DB accounts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Announcing the preview for Intra-account container copy jobs. This functionality helps create offline copies of containers for Azure Cosmos DB for both Core (SQL) API and Cassandra API using Azure CLI. When to use The container copy feature for Azure Cosmos DB is helpful for the following scenarios: Copy all items from one container to [&hellip;]<\/p>\n","protected":false},"author":79038,"featured_media":4773,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[12,16,14],"tags":[1827],"class_list":["post-4772","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcements","category-cassandra-api","category-core-sql-api","tag-container-copy"],"acf":[],"blog_post_summary":"<p>Announcing the preview for Intra-account container copy jobs. This functionality helps create offline copies of containers for Azure Cosmos DB for both Core (SQL) API and Cassandra API using Azure CLI. When to use The container copy feature for Azure Cosmos DB is helpful for the following scenarios: Copy all items from one container to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/4772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/users\/79038"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/comments?post=4772"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/4772\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media\/4773"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media?parent=4772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/categories?post=4772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/tags?post=4772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}