About Linux FAQ

Browse More FAQs:

RHEL / CentOS Linux FTP Cron Job for automatic ftp backup

Posted by Vivek Gite [Last updated: December 6, 2007]

Q. I need help with a cron job. A automatic ftp backup will pickup sql.tar.gz and upload to remote ftp server under CentOS Linux. How do I automate entire procedure to upload file /tmp/backup/sql.tar.gz?

A. You can use standard ftp client for File transfer protocol. The program allows a user to transfer files to and from a remote network site. However, modern FTP client follows little different syntax to upload file.

Here is a quick script:

#!/bin/sh
USERNAME="your-ftp-user-name"
PASSWORD="your-ftp-password"
SERVER="your-ftp.server.com"

# local directory to pickup *.tar.gz file
FILE="/tmp/backup"

# remote server directory to upload backup
BACKUPDIR="/pro/backup/sql"

# login to remote server
ftp -n $SERVER <<EOF
user $USERNAME $PASSWORD
cd $BACKUPDIR
mput $FILE/*.tar.gz
quit
EOF

Make sure script has executable permissions:
$ chmod +x /path/to/ftp.backup.script.sh

Setup a cron job to run script at 15:30 (24 hr clock time) times:
15 30 * * * bash /path/to/ftp.backup.script.sh

Above script should work with all modern ftp client under any Linux / UNIX version.

Related: Increase productivity with FTP autologin and macros and backup related shell script.

E-mail this to a friend      Printable version

Related Other Helpful FAQs:

Discussion on This FAQ

  1. Planet Malaysia Says:

    I think this is not secure.

  2. Wilfred Says:

    Where does it say it’s secure?
    It does the job, period.
    FTP itself isn’t secure

  3. Internet Marketing Legacy Says:

    Hey, this is very helpful. Thank for the script.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.