Creating Date-Stamped Log Files with Grsync

The hard drive of my office Windows 7 PC died yesterday. Stone cold dead, right in the middle of a song I was enjoying on Pandora! Not a big deal, since about the only thing I use the Windows 7 PC is for playing Pandora anyway. It worked out well in the end though, since instead of a dedicated Windows 7 PC, Windows now only takes up a 50 GB partition with plenty of room for whatever Linux distributions that strike my fancy. I was putting off installing Linux on it, but the disk crash gave me the opportunity I needed to bring more Linux into my life.

The disk crash also got me thinking about my Linux Backup processes and that I wanted to add more Grsync jobs to my routine. Oh, I have a bash backup script that I run faithfully, but I hadn't used rsync for a while and it was time to change that.

Our sample Grsync backup job is going to do the following.

  1. Our Grsync Session called “Kingston Mintland” will be run manually. No cron or other automated processing will be involved. We'll be backing up our files to a USB thumb drive called KINGSTON.
  2. Our backup area containing our data files is called Mintland. We're going to back it up but will exclude several directories we don't care about.
  3. We will be writing the rsync output to a log file, but rather than append to an existing log file which is rsync's convention we're going to write an original log file for each backup and add the date of the backup to the log filename for something like backup-[dd-mm-yy].log

To get started here is our Grsync Main Dialog tab.

Here's the Mintland file area we are backing up to the USB Thumb Drive. We're going to exclude several of these directories: backups, lost+found, apps, a hidden directory named .Trash-1000 and transport.

Excluding Multiple Directories

This is one of the main tips of this post, demonstrating how to exclude multiple directories using an rsync exclusion file. If we look on our advanced options screen “Additional options” area at bottom, we are providing a list of directories and files to exclude in the exclusion file /mintland/files/grsync/mintland-excludes.txt. In case you were wondering, the –delete option tells rsync to remove any content on the destination that is no longer in the source /mintland area.

Here's that rsync exclusion file.

Logging the Backup to a Date-Stamped File

Logging the Rsync backup to a date-stamped file can be a little tricky, especially considering that rsync by default appends to a log file and there is no option to overwrite an existing log file. Here is how we'll do it in this Gsync Session.  First we'll add a setting to log the output to a file.  That is shown in the Gsync “Additional Options” settings shown earlier. Then we're going to configure Gsync to run a script at the conclusion of the backup, shown below in Extra Options where we execute

Here is the addFileDate bash script.

The kingstonMintland.log file will be renamed kingstonMintland_[date].log. Here it is at the conclusion of our Grsync backup.

I'm sure many Linux Gurus would prefer to simply write a bash script to perform the entire job, but with Grsync and a few touches us GUI Linux Guys can enjoy the best of both worlds.

More Like This Post