In Linux Operating System cron daemon is used to schedule jobs and commands at regular interval. One can execute any script file containing as a jobs at specified date and time. Following script will use standard Linux FTP commands to place one system’s backup file to other remote system.

Here, the script is working in a cron job which uploads backup file at every 6 hours, then it will overwrite older backup file. If anyone wants to have backup every hour, he/she has to make changes accordingly in crontab file.

Below mentioned script name is: daybackup.script.sh

#!/bin/sh
# Put FTP server details here
SERVER="Remote FTP server"
USERNAME="FTP user"
PASSWORD="FTP password"

# local directory containing source backup file
SOURCEFILES="/home/mybackup"

# remote server directory path in which backup needs to be put in
BACKUPDIRCTORY="/rsystem/backupdir/"

# login to remote server
ftp -n -i $SERVER <<EOF
user $USERNAME $PASSWORD
cd $ BACKUPDIRCTORY

mput $ SOURCEFILES/*.tar.gz
quit
EOF


Make another file using same code given above and give a name to that file as: nightbackup.script.sh as it will put backup to remote system at midnight.
Both the script should have executable permissions, like:

$ chmod +x daybackup.script.sh
$ chmod +x nightbackup.script.sh

Now we have to setup a cron job to run above script at regular intervals.

You need to edit your crontab file. Enter the following command:

$ crontab -e

Following lines should append to available code as there may be a chance to have some another job running in the crontab file.

0 12 * * * daybackup.script.sh >>/tmp/backup.log 2>&1
0 0 * * * nightbackup.script.sh >>/tmp/backup.log 2>&1

Save and close the file.

To store the output of cron commands, we have used /tmp/backup.log file.

Please use crontab –l command to confirm crontab job uses above code or not.

Note: In the above script /home/mybackup folder contains tar.gz files. One has to write a separate script to generate those source backup file.

Can we use such script for Amazon Simple Storage Service (S3) available from Amazon Web Services?