Select to view content in your preferred language

Cloning a site within Hub

868
0
09-16-2024 12:01 PM
RohitSharma-1
Esri Alum
2 0 868

Some of our users have inquired whether it is possible to clone an ArcGIS site within the same organization. While an in-app option is not currently available to perform this action, it can be accomplished using Hub.py. This action will clone the site item and associated site pages and groups. 

Steps to Clone a Site: 

  1.  Create a new Notebook  

      2. Connect to your GIS 

  • The first line in your notebook should contain a pre-populated command to connect to your GIS. Run this cell by clicking the “Run” button on the top ribbon. 

      3. Install the required library 

  • In the next cell, enter the following command and then click “Run”: 

          pip install -e git+https://github.com/esri/hub-py.git#egg=arcgishub 

  • After the installation is complete, click on “Kernel” in the ribbon, and select “Restart” from the options. You will see this message: “Do you want to restart the current kernel? All variables will be lost.” Click “Restart” to proceed. This step installs the required library to complete the task.

      4. Import the Hub Library 

  • In the next cell, enter the following command and run it: 

          from arcgishub.hub import Hub 

  • This will import the necessary Hub module. 

      5. Log in to your ArcGIS account 

  • In the next cell, enter: 

          hub_basic = Hub("https://www.arcgis.com", "Your Username") 

  • Run the cell, and you will be prompted to enter your password. Once you have entered your password, you are authenticated and ready to proceed. 

       6. Fetch the site to clone 

  • In the next cell, enter: 

          site = hub_basic.sites.get('ID of the site that you want to copy') site.item 

  • Run the cell to fetch the site that you want to clone. 

       7. Clone the site 

  • In the next cell, enter: 

          site_cloned = hub_basic.sites.clone(site) site_cloned.item 

  • Run this command to clone the site. You will be provided with a link to the new site.  

 

Note: If you do not have ArcGIS Notebooks, you can run it in your local Jupyter Notebooks.  

In upcoming blogs, I will share the steps to show how you can clone a site across different organizations (Example- Enterprise to Online). Please share your feedback or ideas for further enhancements through the ArcGIS Hub Ideas board in Esri Community.