HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Tips/Tricks/Mods (http://www.howtoforge.com/forums/forumdisplay.php?f=19)
-   -   [SHELL Script] - Backup WEB & DATABASES (http://www.howtoforge.com/forums/showthread.php?t=15337)

vaio1 5th September 2007 15:48

[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.


All times are GMT +2. The time now is 16:15.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.