#!/bin/bash ################################################################################ # # # Copyright (C) 2007 Jack-Benny Persson # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; either version 2 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # ################################################################################ ## Config what to backup and the name of the backup files ## ## Leave the DUMMYFIELD where it is! ## DIRS=("/home/theuser/stuff/" "/home/theuser/webpage/") NAME=("DUMMYFIELD" "stuff" "webpage") IDLETIME=21600 # Number of seconds between backups ## MySQL config ## MYSQL=1 # Set to 1 to enable and 0 to disable MySQL support SQLUSER=thesqluser SQLPASS=mywickedpassword SQLHOST=sql.host.com DBASES=("the_datase_to_be_backuped") ## Basic config ends here - Do not forget to config the FTP below ## ftp_upload() ## The FTP upload routine ## { LOCALFILES=$1 #### FTP setup #### HOST=ftp.host.com USER=theuser PASS=killerpassword LOCALDIR="/home/theuser" # From where you run the script REMOTEDIR="/backup" # Where your want your backups on the server #### FTP setup ends here (all setup/config ends here) #### ftp -n -V $HOST < /dev/null if [ ${?} -ne 0 ] then echo "It seems that you don't have the MySQL-client packaged installed" exit 1 fi fi a=0 for i in ${DIRS[*]}; do let a++ tar -cf backup_${NAME[$a]}.tar ${i} ftp_upload backup_${NAME[$a]}.tar ## Uploading... done if [ ${MYSQL} -eq 1 ] then for j in ${DBASES[*]}; do mysqldump --user=${SQLUSER} --password=${SQLPASS} --host=${SQLHOST} \ ${j} > ${j}.sql ftp_upload ${j}.sql done fi echo -e "\nDone...\nSleeping for ${IDLETIME} seconds until next backup" sleep ${IDLETIME} done