Knowledgebase

Batch/Shell script to download backups through FTP

Posted by fire-host, 12-12-2011, 12:48 PM
Hi All, I'm trying to create a simple batch/shell script to complete the following: 1. Connect to FTP Point 1 (Using log-in credentials) 2. Download pre defined files and folders within the root folder its connected to (displaying size and % it's downloading etc, speed would be a bonus to) 3. END 4. Connect to FTP point 2 (Using its own log-in credentials) 5. Download pre defined files and folders within the root folder its connected to (displaying size and % it's downloading etc, speed would be a bonus to) 6. END I then want to automate this daily perhaps using cron jobs? It will be a Windows XP or possibly linux connecting to a Windows Server FTP in both situations. Can this be done and how would I go about this? Box box it runs off will be set-up fresh then just left in a corner and left to tick over so this needs to be fully automated without prompts. Help really appreciated on this. Read so many articles im all confused! So much different info around sometimes you can just go way to far into it for what should be a relatively easy task!!! Thanks. EDIT: In one of the download instances above, it would be great if it could check what files it has already and just downloading the new ones ... and in the second instance download the same group of files but in new folders with an incrementing number so "Backup 12/12/2011 #1 ... Backup 12/12/2011 #2 ... Backup 13/12/2011 #1 ... etc" Last edited by fire-host; 12-12-2011 at 12:53 PM.

Posted by mike86, 12-12-2011, 12:54 PM
Instead of using FTP, check out rsync. It is designed exactly for what you need. It is complicated to set up exactly how you want it, but once you have it going it works like a dream: http://www.cyberciti.biz/tips/linux-...rectories.html * edit That guide is a bit old. Full definitions of how to use it can be found here: http://www.samba.org/ftp/rsync/rsync.html You can even use --remove-source-files to remove the files from your remote server once they have been synced.

Posted by fire-host, 12-12-2011, 01:00 PM
I was expecting to see Rsync mentioned somewhere ... I just think it may a little too advanced for what we need. I was looking down the FreeNAS + RSYNC route ... I just thought a Batch/Shell would of been easier for this task? Plus I read somewhere that it can be a bit difficult when trying to connect to a remote windows server and bringing the files down locally?

Posted by mike86, 12-12-2011, 02:26 PM
I have setup rsync on linux and windows and both work really well and were not that complicated. Once you get your head around the setup, it works well. What I did was had a cron script that runs every few minutes to do regular checks, but use a lock file so it doesn't try to run lots of instances simultaneously. I ran rsync through a screen session so I could then connect to it at any time and check the progress of the current task.

Posted by fire-host, 12-12-2011, 02:49 PM
Hi Mike, Thanks for that. I know it's a little cheeky to ask but would you be able to go a little more in depth and perhaps take me through a step by step? Sounds a good method! Thanks in advance.

Posted by mike86, 12-12-2011, 03:00 PM
No problem, here is the code you should need once you have rsync setup. I run this cron script every few minutes: I have stuck things in parenthesis that you need to change. you sould get the general jist of how the code works though. The code creates a screen session called "rsync", and runs the rsync command within it. You can then use the command "screen -r rsync" to connect to this screen session at any time and view the progress of the session. Last edited by mike86; 12-12-2011 at 03:03 PM.

Posted by viGeek, 12-21-2011, 05:06 PM
If you're set on using FTP this can be achieved through bash..... Something like this should work.

Posted by mattmackman, 12-28-2011, 03:27 AM
bin/bash #Ex /root/backup BACKDIR=~/backups #----------------------FTP Settings--------------------# FTP=y FTPHOST="ftp.server.com" FTPUSER="username" FTPPASS="pass" FTPDIR="backups" GET_FILE="" #----------------------End of Settings------------------# if [ -e $BACKDIR ] then echo Backups directory already exists else mkdir $BACKDIR fi if [ $FTP = "y" ] then echo "Initiating FTP connection..." cd $BACKDIR ftp -nv <



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
What do you think off? (Views: 566)
MySQL failover (Views: 636)


Language:

Client Login

Email

Password

Remember Me

Search