Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

ODK Central Domain Change: A Painless Backup and Restore Tutorial

Posted on Oct 21 Odk Central is a powerful tool for collecting, managing, and analyzing data using mobile devices. However, there may be situations where you need to move your ODK deployment from one server to another, such as changing hosting providers, upgrading hardware, or switching domains.This tutorial will walk you through the steps of creating a direct backup of your ODK Central database, copying the backup file and other essential data to the destination server, and restoring the backup file on the new server. The tutorial will also show you how to update the domain names in the Enketo Redis databases and config files to avoid errors when previewing forms on the new server.By following this tutorial, you will be able to migrate your ODK deployment from one server to another with minimal downtime and data loss.Before you begin, ensure that you have the following prerequisites:A running instance of ODK Central on the source and destination servers.Both source and destination servers are running the same version of ODK Central.Access to the command line interface (CLI) of both source and destination servers.Sufficient disk space on both servers to store the backup files and other essential data.If you have met these requirements, you will be able to follow this tutorial easily and avoid errors or issues that may arise during the backup and restore process.Log in to your ODK Central source server.From the Terminal window, create a folder odk-backups for the ODK Central backup files in the logged-in user's home folder. You can use a different name that follows your folder naming conventions.Run the command below to perform a direct backup of your ODK Central database. Replace backup-password, your-odk-username@your-odk-domain-name, your-odk-domain-name, and backup-filename.zip placeholder values with actual values for your ODK Central installation.{"passphrase": "backup-password"}: password that will be used to encrypt the backup fileyour-odk-username@your-odk-domain-name: Username that you use to log into the ODK Central web interfaceyour-odk-domain-name: Registered domain name for your ODK Central installationbackup-filename.zip: The name that will be assigned to the backup file.You will be asked to provide your user password before the command can run. The password you type will be the password for the user that you use to log into the ODK Central web interfaceWait for the backup process to run to completion.Below is an example of commands contained in the previous steps.This step is not mandatory, but it helps you understand the source of Docker container names used in this tutorial.On the source server, change directory to the ODK Central installation folderList names and state of ODK Central Docker containers using the following command:--format option will list names and headers of the required fields. \t is a tab character to separate the fields.Running the command will output a list similar to the following:Redis stores data in memory (RAM) which allows for fast data access and retrieval. The ODK Central installation includes two Redis database instances; central-enketo_redis_main-1 and central-enketo_redis_cache-1. To backup the Redis databases, you run commands to flush the in-memory data to disk.Log in to your ODK Central source server if you had logged out.Change directory to the ODK Central installation folderFlush in-memory data to disk on the main instance of Enketo Redis database by running the following command.The command instructs Docker to execute the Redis Command Line Interface (CLI) tool (redis-cli )within the Docker container named central-enketo_redis_main-1 which is listening on port 6379. save creates a snapshot of the current state of the Redis database and writes it to disk.The server should display OK after the command completes and a backup file named enketo-main.rdb will be created in the /data/ folder of the central-enketo_redis_main-1 container.Copy the enketo-main.rdb file from the Docker container to the backup folder you created.Flush in-memory data to disk on the cache instance of Enketo Redis database.The server should display OK after the command completes and a backup file named enketo-cache.rdb will be created in the /data/ folder of the central-enketo_redis_cache-1 container.Copy the enketo-cache.rdb backup file from the Docker container to the backup folder you created.The central-service-1 container has a /etc/secrets folder which contains files used to store secret keys for the Enketo server. These keys are used to encrypt and decrypt data. Copy the secrets folder to the odk-backups folder.The following is an example sequence of the commands and outputs for the above steps.Copy Enketo config file from Docker container to a text file in the backup folder.Open the text file using the nano editor.Using Control + K (^K) keys, remove all key/pair values in the text file except "encryption key", "less secure encryption key", and "api key". After you have completed removing all other key/values pairs, your text file should contain entries similar to the following:Press Control + O (^O) to save the changes.Press ENTER key to confirm the file name.Press Control + X (^X) to close the editor.Log out of the source serverLog in to your ODK Central destination server.If you are using username/password to connect to the source server, run the command below to copy the ~/odk-backups folder to the destination server. You will be prompted to type the user's password before the rsync command starts the syncing process.Use the below rsync command if you use SSH keys to log in to your source server.-a : Archive mode, which preserves file attributes and permissions.-v : Verbose output, so you can see the progress.-z : Compresses data during transfer, reducing the network bandwidth used.-e "ssh -i ssh-key-file" : Tells rsync to use SSH for connecting to the remote server using -i ssh-key-file SSH private key file for authentication.user@remote_server:~/odk-backups/ : user is the username for the remote server while remote_server is the IP address or registered hostname for the remote server. odk-backups refers to the folder containing the backup filles on the remote server.Replace user, remote_server, and ssh-key-file with actual values for your environment.A message and prompt similar to the one below may be displayed if SSH does not have a record of the remote server's public key. Make sure you trust the remote server before typing ‘yes’ to continue connecting.The first time ODK Central runs, it creates the /data/transfer folder on the host server and on the central-service-1 Docker container. The purpose of the folder is to allow exchange of data between the host server and the Docker container. Any changes made to /data/transfer in the central-service-1 container will be reflected in /data/transfer on your host server, and vice versa. To restore the Direct Backup file, you require to place the file in this folder.Log in to your ODK Central destination server if you have logged out.Move the Direct Backup file to the /data/transfer folder using the command below. Replace {backup-filename.zip} with the actual name that you used during the backup process.If you encounter a "cannot create regular file: Permission denied" error, prefix the command with sudo.Change directory to ODK Central installation folder by running the following commands.Before running the command below, be aware that the command will replace all data on the destination server with the backup snapshot data. Once you are certain you want to replace the existing data, restore the backup using the following command:The command tells Docker to go into the running container named service and execute a Node.js script (restore.js) which expects a backup file (backup-filename.zip) and backup password (backup-password).Replace backup-filename.zip with the file name you moved to the /data/transfer/ folder and {backup-password} with the password used during the backup process.If you did not set a backup password during the backup process, press ENTER key immediately after typing the backup filename. Avoid trailing spaces after the filename backup-filename.zip.If the server displays "no configuration file provided: not found", you are running the command outside of ODK Central installation folder.Wait for the backup restoration process to complete. The duration of your wait time will depend on the size of your backup file. After the restore process runs to completion, a success message including tasks that you require to revisit and verify will be displayed.Make sure you are stilled logged in to the destination server and you are working from the ODK Central installation folder.Copy the main Enketo Redis database (enketo-main.rdb) to the Docker container using the following commands:Example commands and output:Copy the Enketo Redis cache database (enketo-cache.rdb) to the Docker container:Copy the secrets folder to the central-service-1 Docker container:Copy the config keys text file to the config folder in the Enketo Docker container.Open a Bash shell in the Enketo Docker container.Install nano editor.-y option will assume "yes" as the answer to any prompts that may occur during the installation process.Open the Enketo config file with the nano editor.Prefix "encryption key", "less secure encryption key", and "api key" keys with # (or any other character). This will help you differentiate between the existing keys from the new keys when updating.Move to the beginning of the file and press the ENTER key after the opening curly brace ({) to create a blank line.Press Control + R (^R) keys. The editor will display a "File to insert [from ./]:" prompt. Type config/enketo-config-keys.txt next to the prompt and press the ENTER key to insert the contents of the file at the cursor location.Move the cursor to the "encryption key" line of the data that has been inserted to the file.Press Control + K (^K) keys to cut the line.Move the cursor to the beginning of "encryption key" prefixed with a # character.Press Control + U (^U) keys to paste.Repeat the previous three steps to update "less secure encryption key" and "api key" values.Remove the lines prefixed with # by moving to each line and pressing Control + K (^K).Save the changes and exit the nano editor.Installation of nano editor was temporarily. Therefore, uninstall the editor and exit the Enketo container using the following commands.Restart the Enketo Docker container to effect the changes in the configuration file.Optionally show the active status of the docker containers.If the ODK Central domain names on the source and destination servers are different, you will encounter the following error when you attempt to preview restored forms on the destination server.This form does not exist or you no longer have access to it. Please check the URL for any missing characters.If the form existed previously, it may have been archived, disabled or deleted. If this is unexpected, please contact the person who asked you to fill the form.(Attempted to access form with ID: )To resolve the error, you must replace the old domain values with the new domain values in the Redis databases.On the destination server, create ~/main-odk-domains.sh script file.Update the file with the following:The script fetches all keys from the Redis database and iterates over each key. For each key, it substitutes any occurrences of old domain values with the new domain values and renames the key in the database. Where the type of key is hash, the value of the openRosaServer field is updated to the new domain.The sed command is used to substitute old domain values with new domain values. The g at the end of the command tells sed to replace all occurrences of OLD_DOMAIN in the key.grep -q command searches for old domain value matches within the key and exits with either a success or failure. The -q option suppresses display of the output.Save the file and exit the nano editor.Make the script file executableCopy main-odk-domains.sh to cache-odk-domains.shOpen cache-odk-domains.sh with a text editor and replace any occurrences of redis-cli -p 6379 with redis-cli -p 6380.Save the changes and exit the editor.Copy the main-odk-domains.sh script file to the main Enketo Redis database Docker container.Open a Bourne shell in the main Enketo Redis database container.Run the script fileOptionally, confirm the update has been successfulExit the Docker containerCopy the cache-odk-domains.sh script file to the cache Enketo Redis database Docker container.Open a Bourne shell in the cache Enketo Redis database containerRun the script fileExit the Docker containerThis tutorial has shown you how to backup and restore ODK Central data. You have learned how to create a direct backup of your ODK Central database, copy the backup file and other essential data to the destination server, and restore the backup file on the new server. You have also learned how to update the domain names in the Enketo Redis databases and config files to avoid errors when previewing forms on the new server.If you found this article useful, please share it with your friends and colleagues who might benefit from it.Thank you for reading!Central Backup RestoreRestoring a backupBackup api call fails after several minutes with ERR_STREAM_PREMATURE_CLOSEFailed to restore ODK central using a downloaded backup fileTrying to migrate my ODK deployment and its data from AWS to Digital OceanI’m running Central on Ubuntu and want to migrate to another serverTemplates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse nabbisen - Aug 7 Daniel Favour - Aug 6 sc0v1n0 - Aug 5 Jonas Scholz - Aug 4 Once suspended, kagundajm will not be able to comment or publish posts until their suspension is removed. Once unsuspended, kagundajm will be able to comment and publish posts again. Once unpublished, all posts by kagundajm will become hidden and only accessible to themselves. If kagundajm is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Kagunda JM. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag kagundajm: kagundajm consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging kagundajm will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

ODK Central Domain Change: A Painless Backup and Restore Tutorial

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×