RHEL / CentOS Linux FTP Cron Job for automatic ftp backup
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:
- HP-UX UNIX: Start / Stop and Configure Cron Services
- Linux / UNIX Setup and run php script as a cron job
- What is Cron?
- Run crontab Every 10 Minutes
- Disable the mail alert by crontab command
Discussion on This FAQ
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!
Tags: automatic ftp backup, backup sql, centos linux, cron job, file transfer protocol, ftp backup script, ftp client, ftp server, upload file



December 6th, 2007 at 7:23 am
I think this is not secure.
February 24th, 2008 at 4:43 pm
Where does it say it’s secure?
It does the job, period.
FTP itself isn’t secure
March 4th, 2008 at 6:31 pm
Hey, this is very helpful. Thank for the script.