Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

A small tool to download db files from Aliyun RDS per schedule

Project description

Aliyun RDS Backup Tool

这是一个按照自定义配置,从阿里云RDS(目前只支持MySQL)下载数据库备份(包括全备和binlog备份)到本地的工具,并支持定时清理过期备份文件。

安装

pip install aliyun-rds-bkp

配置

配置文件为json格式。

{
    "AccessKeyId": "AccessKeyID Provided by Aliyun RDS",
    "AccessKeySecret": "AccessKeySecret Provided by Aliyun RDS",
    "Regions": [
        {
            "RegionID": "cn-hangzhou",
            "DBInstances": [
                {
                    "DBInstanceId": "rm-XXXXXXXXXXXXXXXXXX",
                    "LastFullBackup": {
                        "BackupEndTime": "2019-03-16 05:30:00"
                    },
                    "LastBinlogBackup": {
                        "BackupEndTime": "2019-03-16 05:30:00"
                    },
                    "BackupRetentionDays": 21,
                    "Schedule": {
                        "FullBackup": {
                            "Plan": "* * * * 2,4,6"
                        },
                        "BinlogBackup": {
                            "Plan": "* * * * *"
                        }
                    }
                }
            ]
        }
    ],
    "BackupHome": "Path/to/Backup/Directory",
    "ErrorLog": "Path/to/Error/Log",
    "MailConfig": {
        "SMTPServer": "Your SMTP Server",
        "SMTPLogin": "Account to Login SMTP Server",
        "SMTPPassword": "Password to login SMTP Server",
        "SMTPPort": 25,
        "TTLS": false,
        "From": "email_from",
        "To": [
            "email_1",
            "email_2"
        ],
        "Cc": [
            "email_cc"
        ],
        "Subject": "E-Mail Subject"
    }
}

参数说明

  • AccessKeyId: 阿里云提供的AccessKeyId
  • AccessKeySecret: 阿里云提供的AccessKeySecret
  • RegionID: 参考https://help.aliyun.com/document_detail/40654.html
  • DBInstanceId: RDS实例ID
  • BackupEndTime: 上次备份的结束的UTC时间,用于增量,格式为YYYY-MM-DD HH:MI:SS
  • BackupRetentionDays: 备份保留天数
  • Plan: 备份计划(本地时间)。5个参数以空格分隔,分别代表触发备份的
    • 分钟
    • 小时
    • 一个月中的第几天
    • 月份
    • 一个星期中的第几天。1表示星期一,7表示星期日。
  • BackupHome: 放置备份文件的总目录。在总目录下会自动按照RegionID->InstanceID->Year->Month->Day创建目录
  • ErrorLog: 指定错误日志存放文件
  • SMTPServer: 邮件服务器地址,用于发送备份成功或失败的通知邮件
  • SMTPLogin: 邮件服务器登录账号
  • SMTPPassword: 邮件服务器登录密码
  • SMTPPort: 邮件服务器端口
  • TTLS: 邮件服务器是否使用TTLS,true或false
  • From: 邮件发送账户
  • To: 邮件接收账户列表
  • Cc: 邮件抄送账户列表
  • Subject: 通知邮件的主题

使用

  1. 编写调用脚本
import os

from aliyunrdsbkp.mysql_backup import MySQLBackup

if __name__ == '__main__':
    dir_path = os.path.dirname(os.path.realpath(__file__))
    config_file = os.path.join(
        dir_path,
        'config/settings.json'
    )  # 配置文件路径
    mysql_backup = MySQLBackup(config_file)
    mysql_backup.backup()
  1. 在Linux下的crontab或Windows下的Task Scheduler配置定时执行以上调用脚本

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
aliyun_rds_bkp-0.1.6-py3-none-any.whl (22.6 kB) Copy SHA256 hash SHA256 Wheel py3
aliyun-rds-bkp-0.1.6.tar.gz (8.2 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page