Automated remote backup using ftp commands and cron job

  • Filter
  • Time
  • Show
Clear All
new posts

    Automated remote backup using ftp commands and cron job

    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:

    # Put FTP server details here
    SERVER="Remote FTP server"
    USERNAME="FTP user"
    PASSWORD="FTP password"

    # local directory containing source backup file

    # remote server directory path in which backup needs to be put in

    # login to remote server
    ftp -n -i $SERVER <<EOF

    mput $ SOURCEFILES/*.tar.gz

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

    $ chmod +x
    $ chmod +x

    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 * * * >>/tmp/backup.log 2>&1
    0 0 * * * >>/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?