Last active
January 29, 2018 23:12
-
-
Save allaniftrue/0ad52f931f317872b6a070425ea061bd to your computer and use it in GitHub Desktop.
FreeBSD script to automate MySQL backup and send file to email
This file contains 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 | |
# Credentials | |
DATE=`date` | |
DATABASEUSER=root | |
DATABASEPASS=secret | |
DATABASENAME=test | |
BACKUPMAIL=backup@wordpress.com | |
# For filename purpose | |
PREFIX=test_ | |
NOW="$(date +"%d-%m-%Y")" | |
PATH=/usr/home/freebsd/backup/mysql/ | |
cd ${PATH} | |
# Dump DB | |
/usr/local/bin/mysqldump --opt -u${DATABASEUSER} -p${DATABASEPASS} ${DATABASENAME} > ${DATABASENAME}.sql | |
# Archive for long term storage | |
/usr/bin/tar -zcvf ${PREFIX}${NOW}.tgz *.sql | |
# Zip send to me | |
/usr/bin/gzip -c ${DATABASENAME}.sql | /usr/bin/uuencode ${DATABASENAME}.sql.gz | /usr/bin/mail -s "MySQL DB ${DATABASENAME} for $DATE" ${BACKUPMAIL} | |
#Remove SQL files | |
/bin/rm ${PATH}*.sql | |
# Delete files older than 30 days | |
/usr/bin/find ${PATH}* -mtime +30 -exec /bin/rm {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment