bitnami mysqldump to azure Storage

Ubuntu version here.

Thank you Bing Han for the original.

User my.cnf

vim ~/.my.cnf
[mysqldump]
user=dumper
password=secret

dumper needs to have global privileges @localhost.
root is owner and group of .my.cnf

bitnami my.cnf

vim /opt/bitnami/mysql/my.cnf
!include /home/users_home/.my.cnf

Test it

mysqldump --all-databases > /home/users_home/backups/db-backup.sql

Install Azure-cli

sudo apt-get update
sudo apt-get install nodejs-legacy
sudo apt-get install npm
sudo npm install azure-cli@0.9.4 -g

Backup script

sudo vim /home/user/backup-db.sh
sudo chmod a+x /home/user/backup-db.sh
#!/bin/sh
 
mkdir /home/homedirectory/backups/
export BACKUP_FILE=/home/homedirectory/backups/db-backup.sql.gz
export DATABASE_SCHEMA_NAME=--all-databases
export AZURE_CONTAINER=YOUR_VALUE_HERE
export AZURE_NAME=YOUR_VALUE_HERE
export AZURE_KEY=YOUR_VALUE_HERE
export AZURE_BLOB_NAME=db-production-$(date +%Y%m%d%H%M%S).sql.gz
 
/opt/bitnami/mysql/bin/mysqldump $DATABASE_SCHEMA_NAME > temp.sql
gzip temp.sql
rm -rf $BACKUP_FILE
mv temp.sql.gz $BACKUP_FILE
/usr/local/bin/node /usr/local/bin/azure storage blob -a $AZURE_NAME -k $AZURE_KEY upload --container $AZURE_CONTAINER -f $BACKUP_FILE -b $AZURE_BLOB_NAME

Make sure you reference the full Azure CLI & Node JS path for the azure command. The cron doesn’t know where they are.

Test it

sh backup-db.sh

error: Cannot find module ‘../util/profile/account’
Find and delete the .streamline directory, usually located in your home.

Crontab

Let the machine do the work.

Advertisements