Friday, 30 July 2021

Elasticsearch: Copy Index Structure


Use Case: Let's say, you already have an index on one Server1 and you want to create a new index with the exact structure on Server2. What you should do?

Solution: 

1. Copy the index structure from Server1. Let's say your index name is: product-data-index and you can access the settings here: https://x.x.x.x:9200/product-data-index/_settings

{
"product-data-index": {
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "5",
"provided_name": "product-data-index",
"max_result_window": "30000",
"creation_date": "1627383249968",
"analysis": {
"normalizer": {
"lowercaseNorm": {
"filter": [
"lowercase",
"asciifolding"
],
"type": "custom"
}
},
"analyzer": {
"comma_analyzer": {
"filter": [
"lowercase"
],
"pattern": "(,)",
"type": "pattern",
"tokenizer": "standard"
}
}
},
"number_of_replicas": "1",
"uuid": "cftuOgIPSKWONmbqfICH0w",
"version": {
"created": "7060299"
}
}
}
}
}

Copy this settings JSON

2. Clean the settings JSON.

Now before creating an index, you have to remove few fields from the above JSON

"product-data-index"
"uuid"
"version"
"
creation_date"

and it should look like this.

{
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "5",
"max_result_window": "30000",
"analysis": {
"normalizer": {
"lowercaseNorm": {
"filter": [
"lowercase",
"asciifolding"
],
"type": "custom"
}
},
"analyzer": {
"comma_analyzer": {
"filter": [
"lowercase"
],
"pattern": "(,)",
"type": "pattern",
"tokenizer": "standard"
}
}
},
"number_of_replicas": "1"
}
}
}
}

3. Run this command on Server2 in postman as per the screenshot. You can use any other API Client
which can help you to create the index. You can also use curl.



That's it.


NOTE: To copy data from Server1 to Server2, you can use Reindex API


Thanks!!! Enjoy Programming :)

Monday, 12 July 2021

JamfAAD (Intune) on Macs - Sign-in Errors

 Hi,

Today, I faced one weird problem when I changed my O365 password.




This pop-up was appearing every few minutes after pressing the cancel button and it was throwing me to 404 URL after pressing the continue button which was completely irritating and frustrating.

After spending some time looking into this issue, I found a small trick.

1. Open the Safari browser and make it the default one.

2. Next time when this popup comes, press the Continue button.

That's it and the issue is resolved. :)


Thanks!! Enjoy Programming!! :)



Friday, 2 July 2021

Manual Odoo Migration from One Server to Another



Today, we will go through a step-by-step process to move running odoo from one server to another server

Note: I assume odoo is already installed and working fine with demo/test DB.




Before migrating your Odoo application from one server to another server, it's important to take all the precautionary measures and backup all the data - Database, Code, and Files. Let's start:


I - Backup

Step-1. Database Backup 

You can use Odoo Database Manager - /web/database/manager link to perform this activity. But if the database is too big, please use pg_dump command from PostgreSQL. Here is the example:

pg_dump -W -F t odoo13 > ~/odoo13_28062021.tar

Note: Make sure that you are logged in as postgres or odoo user to perform this activity.


Step-2. Backup of custom modules

The next step is to take a backup of all of your custom code. Mostly, It will be in your /odoo/custom/ and /odoo/enterprise/ directories.

You can use scp command to directly copy your directories from one server to another server. Let's say both of your machines are Linux ones, then these commands can help you.

scp -r(for recursive directories) <source> <destination>

scp -r /odoo/custom/ odoo@x.x.x.x.com:/odoo/


Step-3. Backup of your attachments/images

The last step is to take a backup of your application attachments - order attachments, images attached to tickets, website and product images, etc. You can find the filestore at this location: 

/odoo/.local/share/Odoo/filestore/

You can copy these files also directly to the new server.


II - Restore

Step-1. Restore Database 

You can use Odoo Database Manager - /web/database/manager link to perform this activity. But if the database is too big, please use pg_restore command from PostgreSQL. Here is the command:

pg_restore -v --dbname=odoo13 odoo13_28062021.tar

Note: Make sure that you are logged in as postgres or odoo user to perform this activity and database is already created with name.


Step-2. Restoring custom modules

We have already copied these files in step-2 of the Backup section activity. If not done, please use the scp command to copy files at the new server location.

Note: Make sure that odoo is the owner of all these files. You can use this command to change ownership of the directory and subdirectory.

chown -R odoo:odoo /odoo/custom/


Step-3. Restore filestore

We have already copied these files in step-3 of the Backup section activity. If not done, please use the scp command to copy files at the new server location.


III - Reload Odoo

Once all data - Database, custom modules, and filestore is restored on the new server, the next step is to start odoo with the latest data. I would suggest doing it using the shell/command line if you are a developer.

Step-1. Stop all odoo services

ps ax | grep odoo-bin | awk '{print $1}' | xargs kill -9 $1

Step-2. Start odoo services.

python3 /odoo/odoo-server/odoo-bin -c /etc/odoo-server.conf -d odoo13 -u all

Once all the modules are updated successfully, you can just stop the odoo services using step-1 command and start it using.

sudo service odoo-server start

Step-3. Reload assets - log in as admin and reload assets

I hope everything went well as expected. If your UI is distorted, there is a possibility that fingerprints generated for js and css files are not the same as in filestore. To fix it we have to reload assets.

HTTP://x.x.x.x:8069/web?debug=assets



I hope this POST will help someone, someday and save his/her day!


Thanks!! Enjoy Programming :)