View Single Post
  #1  
Old 5th September 2007, 14:48
vaio1 vaio1 is offline
Senior Member
 
Join Date: Jul 2007
Location: Italy
Posts: 664
Thanks: 77
Thanked 12 Times in 7 Posts
Talking [SHELL Script] - Backup WEB & DATABASES

Hi guys,

I have created a little script on the basis of the: http://www.howtoforge.com/forums/sho...61&postcount=2

This is a shell script that helps you to backup of all WEB SITES & DATABASES and compress them in various GZip file.

All gzip files are located in /home/backup/date[2007/09/05]/

The ISPCONFIG users prefix must be "web". So we have some databases like these:
  • web1_db1
  • web2_db1

and folders like these:
  • web1
  • web2

Now we must create a text file in the root directory and copy and paste this script. Remember to enable the file to the execution [rwxr-xr-x];

Code:
#!/bin/bash
 
DATE=`date +%F`

COPY_TO=/home/backups/$DATE
COPY_FROM=/var/www

DBBACKUPNAME="mysql-"$DATE
WEBBACKUPNAME="website-"$DATE
USER=your_username
PASSWORD=your_password
HOST=your_host

mkdir -p $COPY_TO

echo "";
echo "************************************";
echo "       DATABASES BACKUP";
echo "************************************";
echo "";
for db in $(echo 'SHOW DATABASES;'|mysql -u$USER -p$PASSWORD -h$HOST|grep -v '^Database$'|grep "^web"); 
do
	  mysqldump \
              -u$USER -p$PASSWORD -h$HOST \
              -Q -c -C --add-drop-table --add-locks --quick --lock-tables \
              $db | gzip --best -c > $COPY_TO/$DBBACKUPNAME-$db.sql.gz;
		echo "Backup of" $db;
done;

echo "";
echo "************************************";
echo "       WEB BACKUP";
echo "************************************";
echo "";

echo "Wait a moment please...";
for x in $(find $COPY_FROM -maxdepth 1 -name "web*" -type d -print0 | xargs -0)
do
  tar -cpvzf $COPY_TO/$WEBBACKUPNAME-$(basename $x).tar.gz $x &> /dev/null
done;
echo "Done!";
[root@myserver1 ~]# ./make-backup

************************************
DATABASES BACKUP
************************************

Backup of web11_db1
Backup of web13_db1
Backup of web13_db2
Backup of web13_db3
Backup of web13_db4
Backup of web14_db1
Backup of web14_db2
Backup of web16_db1
Backup of web18_db1
Backup of web7_db1
Backup of web7_db2
Backup of web9_db1

************************************
WEB BACKUP
************************************

Wait a moment please...
Done!
[root@myserver1 ~]#


Any improve of this script is appreciated.

Last edited by vaio1; 5th September 2007 at 15:02.
Reply With Quote
Sponsored Links