Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 25, 2012, 09:56:35 AM

Pages: [1]   Go Down
  Print  
Author Topic: My FTP backup script. Support excluding directories / Database dump (Mysql)  (Read 3523 times)
vivalite
Intergalactic Cowboy
*****
Offline Offline

Posts: 52


« on: June 27, 2007, 08:53:21 PM »

Hi there.
I just wrote a FTP backup script. It should be able to mirror your vhosts folder & MYSQL dumps to LP’s ftp backup server. Very simple. You can setup a cron job for it if you wish to run it every day.


Code:
#!/bin/bash
#
# FTP site mirror script
# by vivalite@gmail.com
#
# Tested on CENTOS 4.2
# Version: 0.1 (Jun-27-2007)
#
# Licence GNU GPL

mysql_username="admin"
mysql_password="******"

ftp_ip="209.200.236.245"
ftp_username="******"
ftp_password="******"

source_dir="/var/www/vhosts"   # No ending slash!
target_dir="backup"            # No ending slash!


#########################
lftp -v > /dev/null 2>&1
if [ "$?" -eq "0" ]
   then

now=`date +%Y_%m_%d`
mysqldump -u "$mysql_username" -p$mysql_password --all-databases | gzip > $source_dir/backup.gz
lftp <<-END
open $ftp_ip
user $ftp_username $ftp_password
##########################
#NOTE: you can edit the mirror section to add your excluding directories
#Format:
#mirror [--exclude SOME_DIR/ --exclude SOME_OTHER_DIR/] ...(pls do not change the rest part of line)
##########################
mirror --exclude SOME_DIR_EXISTS/  --reverse --delete --log=/var/log/FtpBackup_$now.log $source_dir/ $target_dir
exit
END

else

echo "[[[[[lftp is not installed! Please install lftp first!]]]]]"
echo ""
echo "1st:"
echo "wget http://mirror.centos.org/centos/4/os/i386/CentOS/RPMS/lftp-3.0.6-3.i386.rpm"
echo "2nd:"
echo "rpm -i -v -h lftp-3.0.6-3.i386.rpm"
echo ""
echo "Then re-run this script."
exit 0

fi

Save above as a file for example "ftp_backup", filling your username/pw, chmod it to 0700
Run it and follow instructions if action needed.
« Last Edit: June 27, 2007, 09:05:33 PM by vivalite » Logged
Pages: [1]   Go Up
  Print  
 
Jump to: