Skip to content

Instantly share code, notes, and snippets.

@DasLampe
Forked from Ditti4/mysqlbackup.sh
Last active December 19, 2015 00:09
Show Gist options
  • Save DasLampe/5867226 to your computer and use it in GitHub Desktop.
Save DasLampe/5867226 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This file is licensed under the DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004
# See http://www.wtfpl.net/txt/copying/
password=''
mail=''
date=$(date +%m_%d_%Y%H_%M_%S)
if [ ! -d /backup/sql -o ! -w /backup/sql ]; then
if [ $EUID -ne 0 ]; then
echo "Please run script as root or create dir /backup/sql and check permissions"
exit 1
else
mkdir -p /backup/sql
fi
fi
mysqldump --add-drop-database --flush-privileges --all-databases -u root -p${password} > /backup/sql/${date}.sql
echo "See the attachment for the backup. Have fun!"|mutt -s "MySQL backup" -a /backup/sql/${date}.sql ${mail}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment