Download RDS for MySQL backup files using get_rds_backup.py

更新时间:
复制 MD 格式

This topic describes how to use the get_rds_backup.py tool to download backup files for an ApsaraDB RDS for MySQL instance to an on-premises server. You can specify a custom time range. By default, the tool downloads backup files from the previous day.

Take note of the following items:

  • Before you perform high-risk operations such as modifying the configurations or data of your instances, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.

  • Before you modify the configurations or data of an instance, such as an Elastic Compute Service (ECS) instance or an ApsaraDB RDS instance, we recommend that you create snapshots or enable backup for the instance. For example, you can enable log backup for an ApsaraDB RDS instance.

  • If you have granted permissions on sensitive information or submitted sensitive information in the Alibaba Cloud Management Console, we recommend that you modify the sensitive information at the earliest opportunity. Sensitive information includes usernames and passwords.

Prerequisites

  • The ApsaraDB RDS for MySQL instance must use Premium Local SSDs. Cloud disks are not supported.

  • Python 3.7 or later is required.

  • The script runs on Linux, Windows, or any other operating system that supports Python 3.7 or a later version.

Procedure

  1. Install the ApsaraDB RDS SDK for Python on your on-premises server. For more information, see ApsaraDB RDS SDK for Python usage reference.

    # Install the RDS SDK (API version 2014-08-15)
    pip install alibabacloud_rds20140815
  2. Make sure that your on-premises server can access the public endpoint of the ApsaraDB RDS for MySQL instance.

    Note
  3. Download the get_rds_backup.py script to your on-premises server.

    Note

    Specify the RDS instance ID, AccessKey ID, AccessKey secret, and the destination directory for the backup file. The script's comments indicate which parts to edit.

  4. Run the following command to execute the get_rds_backup.py script file:

    python get_rds_backup.py [$RDS_ID] [$Access_Key_ID] [$Access_Key_Secret] [$Backup_Dir]
    Note
    • [$RDS_ID]: The ID of the target RDS instance. You can view the instance ID on the Basic Information page. Example: rm-hp38****2i07.

    • [$Access_Key_ID]: The AccessKey ID of a RAM user. If you do not have a RAM user, create one.

    • [$Access_Key_Secret]: The AccessKey secret of the RAM user.

    • [$Backup_Dir]: The directory where you want to save the backup. Ensure that the target directory has sufficient disk space to prevent download failure.

    • By default, the script downloads the previous day's backup file. To specify a custom time range, modify the starttime and endtime variables in the script.

    The following shows a sample output:

    [root@iZb                        Z ~]# python get_rds_backup.py rm-h        8t LTA        Mn6 sDe        B2d /root
    2020-01-02 2020-01-03
    backfiles:1
    BackupId:501197386 HostInstanceID:100094728 downloadurl:http://rdsb
    _data_20200103032222_qp.xb?OSSAccessKeyId=LTA                                                RvcQ8%3D
    backup file size: 8 M ,fime nema: /roothins100094728_data_20200103032222_qp.xb
         8192  [0.09%]
        16384  [0.18%]
        24576  [0.27%]
        32768  [0.36%]
        40960  [0.45%]
        49152  [0.54%]
        57344  [0.63%]
        65536  [0.72%]
        73728  [0.81%]
        81920  [0.90%]
        90112  [0.99%]
        98304  [1.07%]
       106496  [1.16%]
       114688  [1.25%]

References

Download backups

Applicable scope

ApsaraDB RDS for MySQL