Simple ftp backup script

A category for tips and tricks or off-topic things
Post Reply
jeanmarc
Posts: 1833
Joined: Thu Aug 29, 2013 7:16 am

Simple ftp backup script

Post by jeanmarc » Sun Sep 08, 2013 11:11 am

Hi,

It may be useful to others users, it use lftp :

Code: Select all

#!/bin/bash
# Simple backup script, edit your crontab and add the line
# 0 3 * * * /home/backupplug.sh

LOCKFILE=/var/run/backupplug.pid
if [ -f $LOCKFILE ]; then
CPID="`cat $LOCKFILE`"
fi

if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
   echo "A Plugbox backup is already running as PID:$CPID"
   exit
else 
   echo "Starting to backup Plugbox.."
fi

HOST="www.somehost.com"
USER="yourlogon"
FTPPASS="yourpassword"

LCD="/srv/http/"
RCD="/plugbox/"

# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}

# upload files
lftp -c "set ftp:list-options -a;
open ftp://$USER:$FTPPASS@$HOST;
lcd $LCD;
cd $RCD;
mirror -Re --use-cache"

rm -f ${LOCKFILE}
Save as backupplug.sh. Make sure it is executable (chmod a+x backupplug.sh) Then edit your crontab and add the line 0 3 * * * /path to/backupplug.sh

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests