# Data migration 

# Idea

The idea is to copy all the data of an existent portal , for having a dump that can be used after to restore the data if lost or to use in a new instance.

# Dump the data of a portal

## Steps to flow (inside the server where is the portal to dump)


1. Dumping 4-store data (this command will create a "data" folder containing a dump of the 4store triple store

   ```bash
   sudo 4s-dump http://localhost:8081/sparql/ -a -o <path where to create the data folder>
   ```
2. Gzip the created "**data**" folder and the "**/srv/ontoportal/data/repository**" (where are the original data of the ontologies)

   ```bash
   tar -zcvf backup.tar.gz <path to the data folder> /srv/ontoportal/data/repository
   ```

# Restore and process the data

## Steps to flow (inside the server where is the portal to restore)


1. Copy the backup tar file (4s-dump data + repository folders) into the remote

   ```bash
   scp -r -p  <remote server>:<remote path to the backup tar file> <path where to put the tar file>
   tar -xzvf <path where is the tar file>
   ```
2. Stop ontoportal services :

   ```bash
   sudo systemctl stop 4s-httpd.service
   ```
3. Copy the new repository directory

   ```bash
   cp -fi <path where is the repositroy directory> /srv/ncbo/
   ```
4. Restore the 4store dump

   ```bash
   cd <where is the data directory> && find . -type f | 4s-restore ontologies_api
   ```
5. Restarting ontoportal services

   ```bash
   sudo opstart
   ```
6. Reprocessing all ontologies

   ```bash
   cd /srv/ontoportal/ncbo_cron
   bundle exec bin/ncbo_ontology_process -a 
   ```

---

**Documents**

- [💁‍♂️ Acknowledgments](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/acknowledgments-15GdRXLQdm)
- [📚Publications and references](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/publications-and-references-87tEoeoGKy)
- [🗽Terms & Conditions](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/terms-conditions-naDsDo2Zxq)
- [🧞‍♂️Metadata guidelines and recommendations](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/metadata-guidelines-and-recommendations-pOFbK9sIfp)
- [📜 AgroPortal Release Notes](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/agroportal-release-notes-btKjZk5tU2)
- [ 👩‍🚀 User Guide](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/user-guide-ZszoBwfjGF)
- [📎 API Documentation](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/api-documentation-kMCurGKD97)
- [🤖 Developer Documentation](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/developer-documentation-LhsrucqGTa)
- [🗃External Documentation](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/external-documentation-vNPQCdArrr)
- [AgroPortal infrastructure](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/agroportal-infrastructure-ietsAU4kPs)