Created
January 27, 2017 16:38
-
-
Save tobozo/7c929879409e5b415ac8c030ac3b3836 to your computer and use it in GitHub Desktop.
Crontab to incremental daily/weekly MySQL backups
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 | |
# Greetz to https://twitter.com/JulienLiard for hacking up this script | |
# CRONTAB: | |
# 0 7,10,11,12,13,14,15,16,17,18,19,23 * * 1,2,3,4,5 /home/user/backup_sql/backup_sql.sh >/dev/null 2>&1 | |
# 0 7,15,23 * * 6,7 /home/user/backup_sql/backup_sql.sh >/dev/null 2>&1 | |
#User Variables | |
DATE=/bin/date; | |
SEMAINE=`$DATE '+%U'` | |
JOUR=`$DATE '+%a-%Hh%M'` | |
AUJOURDHUI=`$DATE '+%a'` | |
MYSQLUSER=SCOTT | |
MYSQLPWD=TIGER | |
MYSQLHOST=localhost #par exemple, localhost | |
MYSQLBASE=ORACLE1 | |
MYSQLBACKUPDIR=/home/user/mysqlbackups | |
MK=/bin/mkdir; | |
RM=/bin/rm; | |
GREP=/bin/grep; | |
TAR=/bin/tar; | |
MYSQLDUMP=/usr/bin/mysqldump; | |
#$MK $MYSQLBACKUPDIR | |
if [ ! -d $MYSQLBACKUPDIR/$AUJOURDHUI/ ]; then | |
$MK $MYSQLBACKUPDIR/$AUJOURDHUI/; | |
fi | |
cd $MYSQLBACKUPDIR/$AUJOURDHUI; | |
echo /$AUJOURDHUI/$JOUR.sql | |
$MYSQLDUMP -u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST -Q -c -C --delayed-insert --insert-ignore --disable-keys --add-drop-table --add-locks --quick --lock-tables $MYSQLBASE > $MYSQLBACKUPDIR/$AUJOURDHUI/$JOUR.sql; | |
cd $MYSQLBACKUPDIR/$AUJOURDHUI; | |
$TAR czf $JOUR.tar.gz $JOUR.sql; | |
$RM $JOUR.sql | |
#cd $MYSQLBACKUPDIR; | |
#$TAR czf $AUJOURDHUI.tar.gz $AUJOURDHUI; | |
#$RM -Rf $MYSQLBACKUPDIR/$AUJOURDHUI; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment