Posted by: Mangesh_Linux_Administrator | November 20, 2010

Remote FTP backup script


This script will backup your files from a specific folder to a remote FTP location.

For each day it will create a date directory in the format of d-m-Y (ex:02-11-2008) and store your files there.

You have to create a crontab job to run at least once each day.
Type: crontab -e and paste the following line:
0 0 * * * sh /path/to/script/backup.sh | mail -s “Daily FTP Remote Backup Status” your@mail.com

Create a backup.sh file and chmod +x backup.sh to give it execute permissions.

——————————————————————————————————————-

#!/bin/bash
# FTP Settings
FTPStatus=y
HOST=’hostname’
USERNAME=’username’
PASSWORD=’password’
REMOTEDIR=`date +’%d-%m-%Y’`
HOSTNAME=’/bin/hostname’
LOCALDIR=’/path/to/backup’

### Do not edit below ###

if [ $FTPStatus = “y” ]
then
echo -e “Starting Remote FTP Backup\n”
cd $LOCALDIR
ftp -nv <
open $HOST
user $USERNAME $PASSWORD
mkdir $REMOTEDIR
cd $REMOTEDIR
prompt
binary
mput *.*
quit
EOF
echo -e “Remote FTP transfer completed\n”
fi

———————————————————————————————————————-

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Categories

%d bloggers like this: