Created
November 22, 2015 14:31
-
-
Save Der-Eddy/eabfc22c50e58acd3516 to your computer and use it in GitHub Desktop.
Ubuntu Backup
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 | |
/home/eddy/scripts/sqldump.sh | |
day=`date +%b-%d-%y` | |
srcfolder="/var/nginx/" | |
destfile="/home/eddy/backup/nginx-backup-$day.tar.bz2" | |
tar cfvj $destfile $srcfolder | |
find /home/eddy/backup/nginx-backup-* -mtime +3 -exec rm {} \; |
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 | |
MYSQL_USER="root" | |
MYSQL_PASS="" | |
day=`date +%b-%d-%y` | |
path=/var/nginx/sql/ | |
echo "-- START --" | |
echo "SET autocommit=0;SET unique_checks=0;SET foreign_key_checks=0;" > tmp_sqlhead.sql | |
echo "SET autocommit=1;SET unique_checks=1;SET foreign_key_checks=1;" > tmp_sqlend.sql | |
if [ -z "$1" ] | |
then | |
echo "-- Dumping all DB ..." | |
for I in $(mysql -u $MYSQL_USER --password=$MYSQL_PASS -e 'show databases' -s --skip-column-names); | |
do | |
if [ "$I" = information_schema ] || [ "$I" = mysql ] || [ "$I" = phpmyadmin ] || [ "$I" = performance_schema ] # exclude this DB | |
then | |
echo "-- Skip $I ..." | |
continue | |
fi | |
echo "-- Dumping $I ..." | |
# Pipe compress and concat the head/end with the stoutput of mysqlump ( '-' cat argument) | |
mysqldump -u $MYSQL_USER --password=$MYSQL_PASS $I | cat tmp_sqlhead.sql - tmp_sqlend.sql | gzip -fc > "$path$I-$day.sql.gz" | |
done | |
else | |
I=$1; | |
echo "-- Dumping $I ..." | |
# Pipe compress and concat the head/end with the stoutput of mysqlump ( '-' cat argument) | |
mysqldump -u $MYSQL_USER --password=$MYSQL_PASS $I | cat tmp_sqlhead.sql - tmp_sqlend.sql | gzip -fc > "$path$I-$day.sql.gz" | |
fi | |
# remove tmp files | |
rm tmp_sqlhead.sql | |
rm tmp_sqlend.sql | |
find $path* -mtime +3 -exec rm {} \; | |
echo "-- FINISH --" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment