Oejia 技术栈
首页
应用市场
方案
OE学院
分享
关于
编辑器
登录
如何实现 Odoo 数据每天备份到Amazon S3存储
admin
on 2021-01-29
继承任意已有模型(例如:abc)增加如下方法 ``` @api.model def backup_to_s3(self): import os from datetime import datetime import tempfile import boto from boto.s3.key import Key from odoo.service import db os.environ['S3_USE_SIGV4'] = 'True' def _transport_backup_simple(conn, bucket_name, data, filename): _logger.info('Backing up via S3 simple agent') bucket = conn.get_bucket(bucket_name) k = Key(bucket) k.key = filename k.set_contents_from_string(data) _logger.info('Data successfully backed up to s3') bucket_name = 'A-xxxxxxx' aws_access_key_id = 'B-xxxxxxxxxxxxxxxx' aws_secret_access_key = 'C-xxxxxxxxxxxxxxxxxxxxxx' conn = boto.connect_s3(aws_access_key_id, aws_secret_access_key, host='s3.D-xxxx.amazonaws.com') db_name = self.env.cr.dbname with tempfile.TemporaryFile() as t: db.dump_db(db_name, t) t.seek(0) db_dump = t.read() filename = "%(db_name)s_%(timestamp)s.zip" % { 'db_name': db_name, 'timestamp': datetime.utcnow().strftime("%Y-%m-%d_%H-%M-%SZ") } _transport_backup_simple(conn, bucket_name, db_dump, filename) ``` 其中 A-xxxxxxx、B-xxxxxxxxxxxxxxxx、C-xxxxxxxxxxxxxxxxxxxxxx为S3连接信息;D-xxxx 为 S3 所在可用区名 添加Odoo Cron定时任务,设置每天凌晨n点执行,任务执行Python代码如下: ``` env['abc'].backup_to_s3() ```
Information
如何实现 Odoo 数据每天备份到Amazon S3存储
http://www.oejia.net/article/7ca708cc91e6a4e94d8a177f6424ffaa
http://www.oejia.net/raw/7ca708cc91e6a4e94d8a177f6424ffaa
admin
on 2021-01-29
Category
Odoo
Related
2023-08-27 :
处理 Error Failed to download metadata for repo ‘appstream‘ Cannot prepare internal mirrorlist
2022-05-15 :
fatal
2022-05-15 :
远程登录提示“找不到匹配的keyexchange算法”
2020-03-31 :
基于 Odoo 的公众号客户Portal模块的使用介绍
2018-11-13 :
微信模块 Oejia_wx v0.5.5 发布,优化菜单配置及会话管理增加素材支持
2023-03-07 :
Odoo 更灵活的对账、付款及客户余额的介绍
2019-12-28 :
Oejia_mobile 文档
2022-02-02 :
pylint 用作代码质量检查的基本使用
2022-04-26 :
Odoo商城模块 Oejia_weshop v1.0.1 发布,统一强大的后台多种客户端支持
2020-03-31 :
Odoo 企业微信的OA审批及移动化办公
官方订阅号
关注订阅实时了解我们更多分享
分类
(20)
Django (3)
DjangoX (13)
JS (2)
Nginx (1)
Odoo (134)
Python (1)
YouMd (3)
公告说明 (2)
前端 (2)
后端HTTP (7)
异常处理 (1)
桌面UI (1)
移动开发 (4)
About This Entry
Linux 软件源推荐
Odoo 如何用命令行备份还原数据
About This Blog
main index
to find recently
archives
to find all
标签
微信模块发布记录
微信模块
小程序商城
Web
Http
客服系统
审批OA
HTML5
OE商城
Markdown
DjangoX
解析
oeshop
PyQT
服系统
YouPBX
Excel
示例
md
markdown
Python
最近发布
OSError [Errno 5] Input/output error 异常处理
Odoo context 的常见使用示例
Odoo 符合国人菜单导航习惯的后台主题,支持最新的Odoo17、16等版本,支持企业版!
Odoo 官方应用市场开启 Odoo17 应用的发布!增加了行业应用专栏
Odoo商城模块 Oejia_weshop v1.2 发布,多商户、分销增强,增加商家端!
处理 Error Failed to download metadata for repo ‘appstream‘ Cannot prepare internal mirrorlist
Odoo 16 关键变化 change the term "acquirer" to "provider"
企业微信错误码 81013 的排查与处理
微信模块 Oejia_wx v0.6.7 发布,支持 Odoo16 及新的Websocket消息模式
Friend Links
Oejia技术梦博客分享
YouMd,爱上MarkDown
Mole轻量级wsgi架子