Created
April 8, 2018 09:58
-
-
Save onagatani/d68f7bba443c2878240fc5cbbd974c86 to your computer and use it in GitHub Desktop.
Send mysql dump to Alibaba Object Storage Service (OSS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import oss2 | |
import os | |
import subprocess | |
from datetime import datetime as dt | |
path = '/tmp/mysqldump.sql.gz' | |
result = subprocess.run('mysqldump --defaults-extra-file=/root/.my.cnf --single-transaction --default-character-set=utf8 --all-databases | /usr/bin/gzip > ' + path, shell=True) | |
auth = oss2.Auth ('アクセスキー', 'シークレットキー') | |
bucket = oss2.Bucket (auth, 'リージョンURL', 'バケット名') | |
date = dt.now().strftime('%Y%m%d') | |
remotefile = 'mysqldump.sql.gz.' + date | |
bucket.put_object_from_file(remotefile, path) | |
os.remove(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment