公司之前的附件都是存在微软云的,年底马上到期了,决定迁到华为云,微软云之前存了大量的附件.
解决方案为首先把所有的微软云附件按照原来的后缀和存储结构上传到华为云,然后统一替换数据库中保存的微软云域名前缀链接.
我们公司用的数据库为mysql和mongodb.
关于域名替换,我写了两个demo如下.
UPDATE `testtable`
SET `url`=REPLACE(`url`, 'jiuyuming.xxx.com', 'xinyuming.xxx.com')
WHERE `url` REGEXP 'jiuyuming\.xxx\.com'
UPDATE `表名`
SET `字段名`=REPLACE(`字段名`, '旧的域名前缀', '新的域名前缀')
WHERE `字段名` REGEXP '正则表达式'
mysql替换完毕.
下面是mongodb.
db.attachment.find({'attValue':{'$ne':null}, 'attValue':{'$regex':'xxxx.com'}}).
forEach(
function(item) {
var tmp = String(item.attValue)
tmp = tmp.replace('xxxx.com','chaoxiang.cn')
if (tmp != null){
}
else{
tmp = tmp.join('');
}
item.attValue = tmp
db.attachment.save(item)
}
);
如图,替换成功