Automated File backup and FTP to remote server using cron

This is how to create a tar file with weekday appended on the tar file name.
It will help us to create daily backup and it will also take care of saving the disk space as only last 7 days backup will only be stored.

tar cvvf “login_$(date ‘+%A’).tar” public_html/login/

Following command will now copy the backup file to remote server. In the below example remote server is girishg.net

curl -T login_Sunday.tar ftp://girishg.net/public_html/ –user user:password

It is not a great idea to have the password mentioned in command line, so we can store the username and password in .netrc file and use the command as below.

curl -T login_Sunday.tar ftp://girishg.net/public_html/ -n

.netrc file should be like this

machine girishg.net
login userID
password mypassword

or

machine girishg.net login userID password mypassword
machine abcgdef.com login francis password sw0rdf1sh