-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
37 lines (31 loc) · 1.13 KB
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
#=======================================================================================================================
# VPS Backup Script by Ivan Denkov
#=======================================================================================================================
DATE=$(date +"%Y-%m-%d")
MYSQLDUMP="$(which mysqldump)"
TAR="$(which tar)"
GZIP="$(which gzip)"
PASS="MySQLPSWD"
DIR="/home/backups"
DBS=`mysql -u root -h localhost -p$PASS -e"show databases"`
UPTIME=`uptime`
FREEHD=`df -h`
#This will remove files older than 35 days
find $DIR/* -mtime +35 -exec rm -rf {} \;
$TAR cvf $DIR/Backup-$DATE.tar /var/www
for DATABASE in $DBS
do
if [ $DATABASE != "Database" ]; then
FILENAME=$DATABASE
$MYSQLDUMP -u root -h localhost -p$PASS $DATABASE | $GZIP > $DIR/$FILENAME.sql.gz
$TAR vf $DIR/Backup-$DATE.tar $DIR/$FILENAME.sql.gz
fi
done
#Remove dumped .sql in the folder
rm -rf $DIR/*.sql.gz
#gzip archives
$GZIP $DIR/*.tar
sleep 40
#send me e-mail when done
echo "Email Body - Back Up completed at date $DATE, or maybe not!? Let see the statistic \n\n $UPTIME \n\n $FREEHD" | mail -s "Email Subject - Back UP $DATE" [email protected]