I wanted to create a small easy to use script to back up my most important files several times during the day, using rsync. This example backs up my critical files to an attached hard drive, not a network drive and uses rync 2.6.2.
I had several goals for the script. First, I wanted a small and quick script that I could adopt for several systems. No doubt it is short and easy to configure. Second, I wanted a timestamp so I could review a log quickly that would show that the script did the job right. Third, I choose to use an old hard drive for a local backup instead of a network backup.
Three configuration changes you may want to make. Change to the directory that you need to back up instead of /home/cydo/Docs, use your chosen directory. Second, of course, you need to create a location to back up to. In this example the /bk directory is mounted on a separate hard drive from the one my home folder is on. It really doesn't make much sense to have the backup to the same hard drive. Finally, use touch to create an empty log file: touch sync.log
Here is the script ...use at your own risk...if your cat gets fried when you run this script don't blame me.
#!/bin/sh # # Back-Up Directory TIMESTAMP=`date +%Y%m%d_%H%M%S`; #Year_Month_Day_Hour_Minute_Second echo $TIMESTAMP; /usr/bin/rsync --verbose --stats --recursive /home/cydo/Docs /bk/ /usr/bin/rsync --verbose --stats --recursive /home/cydo/Work /bk/ /usr/bin/rsync --verbose --stats --recursive /home/cydo/Programs /bk/ if [ $? -eq 0 ];then echo "bk_OK_$TIMESTAMP" >> /home/cydo/sync.log fi
Name your script rsync.sh and then do chmod 755 rsync.sh
Now set up a cron job by logging in as root and using the command: crontab -e to edit your cron jobs on the system. I have named the script ./rsync.sh and save your edits.
00 4 * * * /home/cydo/./rsync.sh
That should do it.
Listed Below is the log. Notice that the OK is listed for successful Backups. Be sure to set the correct location for the sync.log on your system.