Guide: Server-to-Server Migration¶
The odoo-data-flow library includes a powerful migrate command designed to perform a direct, in-memory data migration from one Odoo database to another. This is an advanced feature that chains together the export, transform, and import processes into a single step, without needing to create intermediate CSV files on your local machine.
Use Case¶
This command is ideal for scenarios such as:
Migrating data from a staging or development server to a production server.
Consolidating data from one Odoo instance into another.
Performing a data transformation and re-importing into the same database.
The odoo-data-flow migrate Command¶
The migration is handled by the migrate sub-command. It works by exporting data from a source instance, applying an in-memory transformation using the same mapper functions, and then immediately importing the result into a destination instance.
Command-Line Options¶
The command is configured using a set of options that combine parameters from both the export and import commands.
Option |
Description |
|---|---|
|
Required. Path to the |
|
Required. Path to the |
|
Required. The technical name of the Odoo model you want to migrate (e.g., |
|
Required. A comma-separated list of the technical field names you want to migrate. |
|
An Odoo domain filter to select which records to export from the source instance. Defaults to |
|
A dictionary string defining the transformation rules. If omitted, a direct 1-to-1 mapping is used. |
|
The number of parallel workers to use for the export phase. Defaults to |
|
The batch size for the export phase. Defaults to |
|
The number of parallel workers to use for the import phase. Defaults to |
|
The batch size for the import phase. Defaults to |
Full Migration Example¶
Let’s say we want to migrate all partners from a staging server to a production server. We also want to add a prefix to their names during the migration to indicate they came from the staging environment.
Step 1: Create two connection files
You would have two configuration files: conf/staging.conf and conf/production.conf.
Step 2: Define the mapping (optional)
If you need to transform the data, you can define a mapping. For this example, we’ll pass it as a string on the command line. The mapping would look like this in Python:
my_mapping = {
'id': mapper.concat('migrated_partner_', 'id'),
'name': mapper.concat('Staging - ', 'name'),
'phone': mapper.val('phone'),
# ... other fields
}
As a command-line string, it would be: "{'id': mapper.concat('migrated_partner_', 'id'), 'name': mapper.concat('Staging - ', 'name'), ...}"
Step 3: Run the migrate command
You would run the following command from your terminal:
odoo-data-flow migrate \
--config-export "conf/staging.conf" \
--config-import "conf/production.conf" \
--model "res.partner" \
--fields "id,name,phone" \
--mapping "{'name': mapper.concat('Staging - ', 'name'), 'phone': mapper.val('phone')}"
Result¶
This single command will:
Connect to the staging Odoo database.
Export the
id,name, andphonefields for allres.partnerrecords.In memory, transform the data by prepending “Staging - “ to each partner’s name.
Connect to the production Odoo database.
Import the transformed data, creating new partners with the updated names.