This script allows to make a backup of a serie of databases running on a Raspberry Pi. This script is activated as a CRON task (crontab -e) at a frequency to be defined by the user.
#!/bin/bash -e
LOG_FILE='/home/pi/backup_databases.log'
for DATABASE in MONEY SESAME YAMIKAWAN SHOPPING TPMT THRMT wordpress
do
START=$DATABASE"_"
END=".sql"
date=`/bin/date "+%Y-%m-%d"`
BACKUP_NAME=$START$date$END
echo $BACKUP_NAME
DESTINATION="/home/database_backup/"$BACKUP_NAME
echo "Dumping $DATABASE into Destination: $DESTINATION" >> $LOG_FILE
mysqldump -uroot -p15sotong15 $DATABASE > $DESTINATION
if [ $? -eq 0 ]; then
echo "Success at dumping $DATABASE into $DESTINATION" >> $LOG_FILE
else
echo "There was a problem while dumping $DATABASE into $DESTINATION" >> $LOG_FILE
fi
done
exit