• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

Replicate files between two servers

Hi,

I would like to copy a folder of files to another server using ftp at a regular interval. Is this possible and how?
0
amgrobins
Asked:
amgrobins
1 Solution
 
AlexPaceCommented:
If you can use a windows machine you could use this Robo-FTP script to upload all files in a source folder every 15 minutes:
WORKINGDIR "c:\source\folder" 
:top
CRON "@every15min"
FTPLOGON "127.0.0.1" /user="userID" /pw="secret" /servertype=SFTP /trust=all
SENDFILE "*" 
FTPLOGOFF
GOTO top

Open in new window

You'll need to change the source folder and the remote server connection details.
0
 
point_pleasantCommented:
if on unix try

#!/bin/sh
HOST='ftp.users.qwest.net'
USER='yourid'
PASSWD='yourpw'
FILE='file.txt'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0


The above sh script will spew lots of ftp client output to standard output. Even if everything works perfectly, the user running the above script will see lots of incomprehensible text scrolling by quite rapidly. One refinement would send output to different places:

ftp -n $HOST > /tmp/ftp.worked 2> /tmp/ftp.failed <<END_SCRIPT

0
 
dfkeCommented:
Or one can use rsync instead of ftp: http://samba.anu.edu.au/rsync/
0
 
madunixChief Information Security Officer Commented:
add the below rsync script to your crontab
#!/bin/bash
#  [created  by madunix]
#  This script uses Rsync the backup files
#  to a remote server. To use this script
#  you first have to setup ssh to use keys.
#  This elimates the need for a password but
#  still provides security I have ssh on
#  a non standard port so I had to specify
#  the port (ssh -p 2998).
#
#  Simply change the variables list below
#  to match your specifications.
#
#  The Script also logs the transfer time.
#  For automated backup add script to crontab.
# Setup Variables
SOURCEPATH="/usr/source"
DESTPATH="/usr/dest"
DESTHOST="your.ip.or.hostname"
#The user you created with ssh_keys
DESTUSER="copier"
LOCKFILE="/var/lock/rsyncbackup.lock"
LOGFILE="/var/log/rsyncbackup.log"
STARTTIME=$(date +"%s")
# Verfiy the last rsync is not still running
if [ -f $LOCKFILE ]; then
ERRORTIME=$(date +"%d/%b/%Y:%H:%M:%S %Z")
echo "[$ERRORTIME] WARNING rsyncbackup.lock exists, aborting..." >> $LOGFILE
exit 1
fi
# If it finished, create a new lock file
touch $LOCKFILE
# The rsync command (for explanation type rsync --help)
rsync -a --delete --bwlimit=512 --rsh='ssh -p 2998' $SOURCEPATH $DESTUSER@$DESTHOST:$DESTPATH 2>&1 >> $LOGFILE
# Log when the script was run
DONE=$(date +"%d/%b/%Y:%H:%M:%S %Z")
# Log how long it took the script to run
STOPTIME=$(date +"%s")
SECONDS=$(($STOPTIME - $STARTTIME))
echo "[$DONE]finished: - Tranfer took:$(((SECONDS/60)/60)) hours $(((SECONDS/60)%60)) minutes $((SECONDS%60)) seconds" >> $LOGFILE
# Remove lock file
rm -f $LOCKFILE
# END

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now