forked from kminehart/cockroachdb-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
executable file
·28 lines (23 loc) · 936 Bytes
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
date=`date +%Y-%m-%d.%H.%M.%S`
file="${date}-${COCKROACH_DATABASE}.sql"
cat /google-cloud-sdk/path.bash.inc
if [ "${CLOUD_PROVIDER}" = "aws" ]
then
echo "AWS selected. Starting cockroach dump..."
# cockroach dump reads the environment variables
cockroach dump -u ${COCKROACH_USER} --insecure > "/tmp/${file}.sql"
fi
if [ "${CLOUD_PROVIDER}" = "gcp" ]
then
url="https://storage.googleapis.com/${GCP_BUCKET_NAME}/${file}"
# Dump cockroachdb
echo "Dumping database"
/cockroach dump ${COCKROACH_DATABASE} --url ${COCKROACH_URL} > "/tmp/${file}"
echo "Dump completed. Uploading /tmp/${file} to ${url}"
echo "Generating GCP token..."
/google-cloud-sdk/bin/gcloud auth activate-service-account "${GCP_SA_USER}" --key-file=/gcp/key.json
cat "/tmp/${file}"
curl -v --upload-file "/tmp/${file}" \
-H "Authorization: Bearer `/google-cloud-sdk/bin/gcloud auth print-access-token ${GCP_SA_USER}`" \
"${url}"
fi