Skip to content

A simple ftp backup script for webservers

2009 May 1
by dlarmeir

I understand that this script will not meet every server’s needs and is not the most advanced script out there,  however it is a great concept of how to tar and gzip files up for backup to a offsite ftp server. Hope this helps somone!

#!/bin/bash

########################
#Setup script variables#
########################

DATESTAMP=”`date ‘+%d%m%Y’`”
HOST=’yourftpsite’
USER=’yourftpuser’
PASSWD=’yourftppassword’
FILE0=’mysqlbackup.tar.gz’
FILE1=’homebackup.tar.gz’
BACKUP=’/backup’
HOME=’/home’
MYSQL=’/var/lib/mysql’

########################
#Create backup archives#
########################

# Stop mysql
/etc/init.d/mysqld stop
sleep 15

# Load increase warning
wall **High Load – System backup underway for the next few minutes**

# Backup databases
cd $BACKUP
tar cvzf $DATESTAMP.$FILE0 $MYSQL

# Start mysql
/etc/init.d/mysqld start
sleep 10

# Backup web content
cd $BACKUP
tar cvzf $DATESTAMP.$FILE1 $HOME

################################################
#FTP generated backups to offsite backup server#
################################################

# Upload the files
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $DATESTAMP.$FILE0
put $DATESTAMP.$FILE1
quit

# End

END_SCRIPT
exit 0

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS