Ever wanted FTP backups and automation for keeping backups of important file on off-peak time. I always love automation, so machines can do things automatically and help humans 
Ok lets start, create a shell script
Now paste this script and adjust the parameters of ftp host, email address, backup directory, folder to backup.
03 | DIRTOBACKUP=/var/www/html |
05 | LOGFILE=$BACKUPDIR/autoftp.log |
08 | file =$ hostname -backup-` date +%Y-%m-%d-%H-%M`.tgz |
09 | time =` date +%Y-%m-%d-%H:%M:%S` |
11 | echo "###################################################" > $LOGFILE |
12 | echo "# Start Date&Time $time #" >> $LOGFILE |
13 | echo "###################################################" >> $LOGFILE |
14 | echo "# Backup Process Started #" >> $LOGFILE |
15 | echo "###################################################" >> $LOGFILE |
16 | echo [$ time ] $ file created >> $LOGFILE |
17 | tar cpzf $ file $DIRTOBACKUP |
18 | time =` date +%Y-%m-%d-%H:%M:%S` |
19 | echo [$ time ] backup compressed now sending to ftp server >> $LOGFILE |
28 | mail -s "Backup Report" $EMAIL < $LOGFILE |
Save the file in any place you like, in this example I am saving it to my home directory, i.e. /home/bshafiq/autoftp
Give execute permission to newly created shell script by doing this:
For providing FTP authentication details, “.netrc” text file with ip userid password details in user root folder
like this:-
and paste details like this:-
machine IP_Address login Your_UserID password Your_Super_Strong_Password
Final step add to crontab
(Change root with anyother user of your choice, but the user must have access to the folders we want to backup and where we put the backup)
1 | 0 1 * * * /home/bshafiq/autoftp > /dev/null |
(It will auto backup on 1am daily, adjust the time as your want)
Check the crontab is ok?
Make sure crontab service is running
That’s it ! Enjoy auto ftp backups 