Setting Up Scheduled Tasks in Ubuntu Linux

Michael Mann
Maintaining a backup of important items is essential these day. Still far too many do not take the time to perform backups. I should know as I have been counted myself under that group for some time now. We will be looking at using several items to assist us in creating a schedule task under Ubuntu Linux.

Step 1: Create a simple backup script

Using bash scripting, we will work to create a simple backup script which will do several things: 1) capture the date, 2) create a compressed copy of what we want to backup, 3) copy the compressed copy to the desired location, and 4) remove the compressed copy from the original location. Simply put, we are going to create a compressed copy and put it where we want it.

Here is a basic example of the bash script we will be using (copy and save the script as backup.sh in your backup location):

#!/bin/sh
## Script to backup Thunderbird
set -x
x=`date +%Y-%m-%d` ## Backup needs a date (stamp)

## Create an archived copy
tar zcf thunderbird-${x}.tgz /home/michael/.thunderbird

## Place the archived copy in the thunderbird folder
cp thunderbird-${x}.tgz /home/michael/Backups/thunderbird

## Remove original copy as we don't need two
rm ./thunderbird-${x}.tgz

Make sure to change the file permission to allow the script to executed as a program. This can be done through Nautilus by right clicking the file and choosing Properties. Select the Permissions tab, place a check mark where you see "Allow executing file as program" and click Close.

In this simple backup script, we are creating a tgz copy of the files used for Mozilla Thunderbird. First we capture the date (x) and use it to create the file name. Since the script is used to backup more than one item (not listed here) it is placed inside a folder titled Backup. A sub folder of Thunderbird exists, so the file is moved there and then removed from the main folder.

Note: If you are using a different location for your backups, change the paths to the file in line 4 and the backup locations in lines 4,5 and 6.

Keep in mind, you could add in other items to be backed up inside this script. For instance, I use it to backup Firefox, Pidgin, and Filezilla in addition to Thunderbird.

Step 2: Schedule the Backup

Cron is the tool used to schedule tasks in Ubuntu Linux. This is a command line tool, so we will be looking at Gnome Scheduler, a front-end GUI for cron. If you do not already have cron and Gnome Scheduler installed, install them using your chosen method for installing from the repositories. It will be placed in the System Tools folder under the Application menu.

Open Gnome Scheduler and click New in the top left corner. For our purposes, we will be creating a recurrent task (one that happens over and over again) so select "A task that launches recurrently". There are several items you will need, so let us look at an example. Using the script to backup Thunderbird, assuming the path to the backup file is /home/[user]/backups/backup.sh, let us set up a weekly backup to run on Mondays at 2:30 PM.

Description: Weekly Thunderbird Backup
Command:
sh /home/[user]/backups/backup.sh

Leave as using the default behavior

Select Advanced under date & time and enter the following:

Minutes: 30
Hour: 14 (0 - 23, since it uses a 24 hour clock)
Day: *
Month: *
Weekday: 1 (0 - 7, with 0 as Sunday)

Click Add

You will be prompted about recurrent tasks being run from the home folder (/home/[user]) which is fine. Click OK

You should now have everything setup to run weekly backups of Thunderbird.

Published by Michael Mann

With over 12 years of professional experience as a Web designer and over 25 years of general computer experience, I am often the resident tech . I own and operate Michael Mann Desktop Publishing, a desktop p...  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.