Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Backup for most Linux distro's


  • Please log in to reply
No replies to this topic

#1 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:05:53 AM

Posted 11 September 2009 - 05:56 AM

Well, here's the story, i needed a backup for a webserver (CentOS5.2) that backed up mySQL and directories that i specified, ftp'd them to TWO ftp servers and emailed me the result. I couldn't find one that would do it, so i gathered idea's from other scripts that i found until i ended up with this (NOTE: all credit goes to original authors, i just complied it into one...) :

#!/bin/sh
#Script Modified Maintained by Bradly Sharpe
#ALL CREDIT BELONGS TO ORIGINAL AUTHORS
#Version 0.2
#--------------------------------------------------------------------------

### START OF USER CONFIGURATION ###

### System Setup ###
DIRS="/opt/data /var/www/html"		#Directories to backup
NOW=$(date +"%d-%m-%Y")			   #Date format applied to backups 
BACKUP=/etc/backup/$NOW			   #Where backups are stored before FTP
INCFILE="/root/tar-inc-backup.dat"	#Leave as is

### MySQL Setup ###
MUSER="mySQLuser"					 #mySQL Username (must have suffice permissions
MPASS="mySQLpass"					 #mySQL Password
MHOST="mySQLhost"					 #mySQL Host (localhost, 192.168.0.x) 
MYSQL="$(which mysql)"				#Leave as is
MYSQLDUMP="$(which mysqldump)"		#Leave as is
GZIP="$(which gzip)"				  #Leave as is

### FTP server Setup ###
NCFTP="$(which ncftpput)"			 #Leave as is (Uses ncftp client)

### FTP SERVER 1 ###
FTPD="/directory"					 #Directory on FTP server to save files to
FTPU="ftpuser"						#FTP username
FTPP="ftppass"						#FTP password
FTPS="serverIP"					   #FTP server hostname or IP

### FTP SERVER 2 ###
#FTPD2="/directory"					#Same as above
#FTPU2="ftpuser"					   #Uncomment here and section
#FTPP2="ftppass"					   #below to FTP to multiple
#FTPS2="serverIP"					  #FTP servers.


### Email Configuration ###
MAILADDR="emailaddress"				#Where to send backup email

### END OF USER CONFIGURATION ###

### Start Backup for file system ###
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :


FILE="FileSystem-$NOW.tar.gz"
tar -g $INCFILE -zcvf $BACKUP/$FILE $DIRS


### MySQL Databases Backup ###
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
 FILE=$BACKUP/mysql-$db.$NOW.gz
 $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done


### Dump backup using FTP SERVER 1 ###
ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF
mkdir $FTPD
mkdir $FTPD/$NOW
cd $FTPD/$NOW
lcd $BACKUP
mput *
quit
EOF

### Dump backup using FTP SERVER 2 ###
#ncftp -u"$FTPU2" -p"$FTPP2" $FTPS2<<EOF
#mkdir $FTPD2
#mkdir $FTPD2/$NOW
#cd $FTPD2/$NOW
#lcd $BACKUP
#mput *
#quit
#EOF

### Did ftp backup failed? ###
if [ "$?" == "0" ]; then
 mail -s "Backup Finished Successfully" $MAILADDR < /dev/null
 rm -rf $BACKUP
else
 mail -s "Backup Failed" $MAILADDR < /dev/null
fi

Simply comment out the bits you won't use...

Save as filename.sh
Remember to chmod +x filename.sh and add it into cron for automated backup.

Edited by KamakaZ, 11 September 2009 - 05:59 AM.

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


BC AdBot (Login to Remove)

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users