创建 service key,步骤如下:
iam & admin -> create service account -> 下载 json 文件, 改名(/home/backup/key)
bucket: 目录 mysql-backup 已经被创建
#!/bin/sh
d=`date +%Y%m%d`
h=`hostname`
password=hide
path="/home/backup"
f="${path}/wholedb"
dest="gs://mysql-backup/${h}/${d}/database_backup/"
echo $dest
# get backup file of whole database
/usr/bin/mysqldump --all-databases --user=root --password=${password} --result-file=${f}
# upload to bucket
/usr/local/bin/gcloud auth activate-service-account --key-file ${path}/key
/usr/local/bin/gsutil -q cp -c ${f} ${dest}
/bin/rm ${f}