Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexwybraniec/baaec7116232b000f0ad03841b88e515 to your computer and use it in GitHub Desktop.
Save alexwybraniec/baaec7116232b000f0ad03841b88e515 to your computer and use it in GitHub Desktop.
Bash script of backing up multiple dbs
#!/bin/bash
_dbusername="my_backup_username"
_dbpassword="my_backup_password"
_output="/home/dbbackup/_database_backups"
_dow="$(date +'%A')"
declare -a arr=("my_db_1" "my_db_2" "my_db_3")
for i in "${arr[@]}"
do
echo "$i"
_daily="${i}_${_dow}.sql"
rm -f $_daily
rm -f ${i}_latest.sql
mysqldump --hex-blob -u${_dbusername} -p${_dbpassword} ${i} > ${_output}/${_daily}
cp ${_output}/${_daily} ${_output}/${i}_latest.sql
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment