Created
April 26, 2021 18:05
-
-
Save zdenulo/c0725e7599f57f2598ba200d34fb2e31 to your computer and use it in GitHub Desktop.
bash script to export MySQL database and upload to Cloud Storage bucket
This file contains hidden or 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
| #!/bin/bash | |
| DUMP_FOLDER="/tmp" | |
| GCS_BUCKET="my-gcs-bucket" | |
| DT=$(date "+%Y%m%d") | |
| function backup() { | |
| database=$1 | |
| filename="${database}_${DT}.sql" | |
| output_file="${DUMP_FOLDER}/${filename}" | |
| echo $output_file | |
| sudo mysqldump "$database" >"$output_file" | |
| if test -f "$output_file"; then | |
| gsutil cp "$output_file" "gs://${GCS_BUCKET}/${database}/${filename}" | |
| echo "${database} dump uploaded" | |
| else | |
| echo "No dump file ${output_file}" | |
| fi | |
| } | |
| backup my-db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment