Created
July 6, 2015 08:38
-
-
Save Bogdaan/ae5b20d0f0b81d4edd88 to your computer and use it in GitHub Desktop.
backup files and mysql base
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 | |
PROJNAME= #Имя проекта | |
CHARSET= #Кодировка базы данных (utf8) | |
DBNAME= #Имя базы данных для резервного копирования | |
DBFILENAME= #Имя дампа базы данных | |
ARFILENAME= #Имя архива с файлами | |
HOST= #Хост MySQL | |
USER= #Имя пользователя базы данных | |
PASSWD= #Пароль от базы данных | |
DATADIR= #Путь к каталогу где будут храниться резервные копии | |
SRCFILES= #Путь к каталогу файлов для архивирования | |
PREFIX=`date +%F` #Префикс по дате для структурирования резервных копий | |
#start backup | |
echo "[--------------------------------[`date +%F--%H-%M`]--------------------------------]" | |
echo "[----------][`date +%F--%H-%M`] Run the backup script..." | |
mkdir $DATADIR/$PREFIX 2> /dev/null | |
echo "[++--------][`date +%F--%H-%M`] Generate a database backup..." | |
#MySQL dump | |
mysqldump --user=$USER --host=$HOST --password=$PASSWD --default-character-set=$CHARSET $DBNAME > $DATADIR/$PREFIX/$DBFILENAME-`date +%F--%H-%M`.sql | |
if [[ $? -gt 0 ]];then | |
echo "[++--------][`date +%F--%H-%M`] Aborted. Generate database backup failed." | |
exit 1 | |
fi | |
echo "[++++------][`date +%F--%H-%M`] Backup database [$DBNAME] - successfull." | |
echo "[++++++----][`date +%F--%H-%M`] Copy the source code project [$PROJNAME]..." | |
#Src dump | |
tar -czpf $DATADIR/$PREFIX/$ARFILENAME-`date +%F--%H-%M`.tar.gz $SRCFILES 2> /dev/null | |
if [[ $? -gt 0 ]];then | |
echo "[++++++----][`date +%F--%H-%M`] Aborted. Copying the source code failed." | |
exit 1 | |
fi | |
echo "[++++++++--][`date +%F--%H-%M`] Copy the source code project [$PROJNAME] successfull." | |
echo "[+++++++++-][`date +%F--%H-%M`] Stat datadir space (USED): `du -h $DATADIR | tail -n1`" | |
echo "[+++++++++-][`date +%F--%H-%M`] Free HDD space: `df -h /home|tail -n1|awk '{print $4}'`" | |
echo "[++++++++++][`date +%F--%H-%M`] All operations completed successfully!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment