Automated Incremental Backups With Rsync And Cron (Part 2)
In Part 1 of this tutorial, we covered how to configure rsync so we can backup our important files. Now we will use Cron to automate our backup, so we don’t have to worry about remembering!
In Part 1 of this tutorial, we covered how to configure rsync so we can backup our important files. Now we will use Cron to automate our backup, so we don’t have to worry about remembering!
When deciding what you want to backup, you may want find that you only want to backup certain parts of a directory. For example, you may want to backup your pictures, documents, etc. in your home folder but not temp files, config files, etc. No problem. In rsync, this is accomplished by using include and exclude rules.
If you don’t want to save everything in your /directory/to/copy/, you will most definitely want to use an exclude file, and you may use an include file as well. The reason you may not use an include file is that include may not do exactly what you think it will. For instance, if you only want to save your pictures and documents in your home folder, you can’t just tell rsync to include pictures and documents. This is because everything in /directory/to/copy/ is automatically included the backup. Therefore, if you tell rsync to backup your home folder and then also tell it to include pictures and documents, it will still backup your entire home folder. Include rules are not worthless, however, as they can override exclude rules. If this doesn’t make sense now, don’t worry the following examples will explain the weirdness more concretely.
Have you heard the one about 3-2-1 backups? It’s the idea that you should have 3 copies of your files stored on 2 different mediums and one of the copies should be off-site. I’m not quite there yet, but I’m a little closer now. I have been using rsync, a utility for making incremental backups, for awhile, but I’ve always run the script I created for it manually. I typically did this every three to four weeks, you know when I thought about it. Yesterday I finally created a cron job to automate this process, and it is so much nicer. Read on to learn for yourself how to automate your backups on Linux. Part 1 of this article covers rsync. Part 1a covers include and exclude rules for rsync, and Part 2 covers cron.