Created
February 25, 2016 22:18
-
-
Save Tantas/1dd0895785a3efe15c18 to your computer and use it in GitHub Desktop.
mysql_backup.sh
This file contains hidden or 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 | |
DUMP_DIR="<dump_dir>" | |
MYSQLDUMP="/usr/bin/mysqldump" | |
DUMP_FILE_PREFIX="<database>_dump" | |
dump_date=`date +"%Y%m%d-%H"` | |
dump_file="${DUMP_FILE_PREFIX}_${dump_date}.sql" | |
if [ ! -d "$DUMP_DIR" ]; then | |
echo "error: Dump directory not found: $DUMP_DIR" | |
exit 1 | |
fi | |
cd $DUMP_DIR | |
# Dump db | |
$MYSQLDUMP -u root -p'<password>' <database> | gzip -9c > $dump_file.gz | |
# Define older than in days | |
olderThan=30 | |
# Delete files old files | |
find . -name "*.sql*" -mtime +$olderThan -type f -exec rm -rf {} \; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment