Skip to content

Instantly share code, notes, and snippets.

@vuthaihoc
Created October 12, 2021 18:26
Show Gist options
  • Save vuthaihoc/07c2f1160d19c22fe43e4548dd8e2fe7 to your computer and use it in GitHub Desktop.
Save vuthaihoc/07c2f1160d19c22fe43e4548dd8e2fe7 to your computer and use it in GitHub Desktop.
Dump db and put to s3 by minio client
#!/bin/bash
# file /var/www/backup.sh
# Run `cd /var/www && sh backup.sh`
# This script is used for laravel projects deployed by deployer php
function run_backup(){
export $(cat current/.env | sed 's/#.*//g' | xargs)
export MYSQL_PWD=$DB_PASSWORD
export TODAY=`date +%Y%m%d`
echo "Dumping database"
mysqldump -u $DB_USERNAME $DB_DATABASE \
--no-tablespaces \
--single-transaction=TRUE --verbose | \
gzip > $DB_DATABASE.$TODAY.sql.gz && \
echo "Uploading" && \
mc cp $DB_DATABASE.$TODAY.sql.gz play/bucket/db1month/$DB_DATABASE.$TODAY.sql.gz && \
rm -f $DB_DATABASE.$TODAY.sql.gz
}
dirs=($(find . -maxdepth 1 -type d -name 'deploy.*'))
for dir in "${dirs[@]}"; do
cd "$dir"
pwd
run_backup
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment