简体   繁体   中英

move/copy AWS RDS manual snapshot( postgres) to AWS s3 bucket

How can we save AWS RDS manual snapshots on the s3 bucket(on the same account)? Is Aws will charge for automated RDS snapshots?

Do you guys have a solution for this?

Thanks in advance.

How can we save AWS RDS manual snapshots on the s3 bucket(on the same account)?

You cannot. AWS does not provide access to the raw data of snapshots.

Is Aws will charge for automated RDS snapshots?

Yes, AWS charges for the storage space that snapshots use.

RDS snapshots are only accessible through the RDS console / CLI.

If you want to export data to your own S3 bucket, you'll need to grab that information directly from the database instance. Something like a mysqldump , etc

If you use automated snapshots then AWS will charge you for those.

This is a script i've used in the past to backup a MySQL/Aurora RDS to an S3 bucket:

#!/usr/bin/env bash

set -o errexit
set -o pipefail
set -o nounset

function log {
  echo "[`date '+%Y-%m-%d %H:%M:%S.%N'`] $1"
}

: ${MYSQL_USER:=root}
: ${MYSQL_PASS:=root}
: ${MYSQL_HOST:=127.0.0.1}
: ${MYSQL_PORT:=3306}

if [ -z "${AWS_S3_BUCKET-}" ]; then
    log "The AWS_S3_BUCKET variable is empty or not set"
    exit 1;
fi;

EXCLUDED_DATABASES=(Database information_schema mysql performance_schema sys tmp innodb)

YEAR=$(date '+%Y')
MONTH=$(date '+%m')
DAY=$(date '+%d')
TIME=$(date '+%H-%M-%S')

if [ -z "${MYSQL_DATABASE-}" ]; then
    DATABASES=$(/usr/bin/mysql --host="$MYSQL_HOST" --port="$MYSQL_PORT" --user="$MYSQL_USER" --password="$MYSQL_PASS" -e "SHOW DATABASES;" | cut -d ' ' -f 1)
else
    DATABASES=("$MYSQL_DATABASE")
fi;

for DATABASE in $DATABASES; do

  for EXCLUDED in ${EXCLUDED_DATABASES[@]}; do
    if [ "$DATABASE" == "$EXCLUDED" ]; then
      log "Excluded mysqlbackup of $DATABASE"
      continue 2
    fi;
  done

  log "Starting mysqlbackup of $DATABASE"

  AWS_S3_PATH="s3://$AWS_S3_BUCKET/path-to-folder/$DATABASE.sql.gz"

  mysqldump --host="$MYSQL_HOST" --port="$MYSQL_PORT" --user="$MYSQL_USER" --password="$MYSQL_PASS" "$DATABASE" | gzip | AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY aws s3 cp - "$AWS_S3_PATH"

  log "Completed mysqlbackup of $DATABASE to $AWS_S3_PATH"

done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM