当前位置:网站首页>Cloudbase database migration scheme
Cloudbase database migration scheme
2022-06-24 08:32:00 【songs of the people of Chu】
Function is introduced
Migration between cloud development database environments has always been a difficult problem , although SDK For a single set export and import, But to achieve the migration of the entire database is just 100 The first of the steps , The scheme is to introduce a method of A The environment database is migrated to B The idea of environmental database , For reference only .
Preparation needed
- Deploy the functions under the folder to the corresponding environment
- Created A Environment and B Environmental Science
- If the migrated environment is under another account , You need another account secretID and secretKey, And in init The two fields are added to the environment
- You can operate directly on the cloud development console , There is no need to initiate a call
- Set the timeout of the function to 900 second .
Resources used
- Cloud functions for both environments
- Cloud databases for both environments
- Cloud storage for the target environment
Function introduction
migrate
Migration functions , To be deployed to In a migrated environment
Remember to revise demo Environment in ID For your own environment ID
It is necessary to initiate the call , No parameters required .
It will be called exportDatabase Function to export data , And get an array of return values , The data format is roughly as follows
[
{
"result": {
"CollectionName": "test2Collection",
"exportRes": {
"JobId": 102223492,
"RequestId": "332f1595-9b64-4a42-a6b3-a0ca1e0b50e5"
}
},
"requestId": "ff84c3dc-d3fa-11eb-bb41-525400be5245"
},
{
"result": {
"CollectionName": "testCollection",
"exportRes": {
"JobId": 102223493,
"RequestId": "92b8e0b5-e4a9-43bd-b9ef-37e6abca8b83"
}
},
"requestId": "004ba931-d3fb-11eb-a0a6-52540096f86f"
}
]And then call copyDatabase, Migration
exportDatabase
The export function , To be deployed to In a migrated environment
By migrate call
copyDatabase
To be deployed to In a migrated environment
By migrate call
{
JobIdList:Array
}This function will initiate a call importDatabase, If returns success, The migration is successful .
importDatabase
Import function , To be deployed to Migrate to the target environment
This function receives CollectionName Function for collection import , Users do not need to actively invoke , The function is copyDatabase call .
Sequence diagram
Complete steps
- Deploy the function to the corresponding environment ( except importDatabase Is deployed to the target environment , The remaining three are migrated environments ), Remember that cloud installation depends on .
- call migrate( It is recommended that the console directly call )
- Wait for the return value
- Go to the new environment database to view the migration results
matters needing attention
- because export This interface can only be called once per second , So to be on the safe side , At the code level, each set is exported every second . therefore migrate This function will take a long time to call , It is recommended to wait patiently ( Every set needs about 2 second ), If the number of sets is large , It is recommended to adjust the function timeout upwards . If greater than 900 second , Consider using cloud hosting to implement .
- migrate All logic will be executed at once , Long running time , Please be patient , You can do other things while waiting .
- The export of each document is asynchronous and takes time , obtain migrate After the return value of , Please wait a while before calling copyDatabase, Since the size of each document is variable, the time is uncertain , But in copyDatabase Detection function is built in , If the call is initiated before the full export , This function will stop and prompt which item has not been exported yet , You can call .
- return success after , Go to the console to check that the collection has been created , But the number of documents is 0 The situation of , This is because the import is an asynchronous event , Creating collections and importing documents are not done at the same time , Just wait for a while .
- The number of documents is 0 Will be skipped .
- If a system error occurs , Internal errors, etc , You can appropriately increase the cloud function running memory .
- if migrate The function console appears ESOCKETTIMEDOUT Or other errors , But the other three functions all work well , That can be ignored , It depends on whether the database data of the target environment is migrated correctly .
- The cloud storage of the target environment is borrowed as the medium , If it is too large, it can be deleted , The catalogue is /tmp/db-imports
- Not rigorously tested , I don't know the performance limit yet , Current test 20+ aggregate , Hundreds of documents are OK .
Open source code
边栏推荐
- 13 -- 移除无效的括号
- How to use the virtual clock of FPGA?
- os. path. Pits encountered during the use of join()
- etcd备份恢复原理详解及踩坑实录
- 小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现
- ZUCC_ Principles of compiling language and compilation_ Experiment 04 language and grammar
- ZUCC_ Principles of compiling language and compilation_ Experiment 08 parsing LR parsing
- jwt(json web token)
- Export MySQL database to xxx SQL, set xxx The SQL file is imported into MySQL on the server. Project deployment.
- Promise usage scenarios
猜你喜欢

1279_ Vsock installation failure resolution when VMware player installs VMware Tools

2021-03-11 COMP9021第八节课笔记

自动化测试的未来趋势

5 minutes, excellent customer service chat handling skills

How to improve the customer retention rate in the operation of independent stations? Customer segmentation is very important!

JUC personal simple notes

新技术实战,一步步用Activity Results API封装权限申请库

【无标题】

2021-03-11 comp9021 class 8 notes

The article takes you to understand the security of Windows operating system and protect your computer from infringement
随机推荐
[real estate opening online house selection, WiFi coverage temporary network] 500 people are connected to WiFi at the same time
Promise usage scenarios
基金的募集,交易与登记
Final review and key points of software process and project management
论文笔记: 多标签学习 DM2L
js滚动div滚动条到底部
Pat 1157: school anniversary
2022年制冷与空调设备运行操作上岗证题库及模拟考试
Ordinary token
ZUCC_编译语言原理与编译_大作业
2021-03-09 COMP9021第七节课笔记
ZUCC_编译语言原理与编译_实验05 正则表达式、有限自动机、词法分析
Industrial computer anti cracking
2021-03-11 comp9021 class 8 notes
etcd备份恢复原理详解及踩坑实录
WCF TCP protocol transmission
Introduction to RCNN, fast RCNN and fast RCNN
jwt(json web token)
Scénarios d'utilisation de la promesse
QPS, TPS, concurrent users, throughput relationship