PDA

View Full Version : Cron Job



carnold6
18-Apr-2012, 02:03
SLES11 SP2. I need to create a cron job that will run a rsync backup nightly. I have a script:

#!/bin/bash

#Script to backup ELC's Share folder to off-site NAS through VPN (Tek-Nerds).
#Specify the mount point here
mount_point='/mnt/backup'

echo "####"
echo ""
#Check to see if the NAS is mounted and if not mount it.
if ! mountpoint -q ${mount_point}/; then
echo "Mounting the NAS"
echo "Mount point is ${mount_point}"
if ! mount ${mount_point}; then
echo "An error was returned by the mount command!"
exit 5
else echo "Mounted successfully";
else echo "${mount_point} is already mounted";
fi

#Target must be mounted at this point, or job dies
if ! mountpoint -q ${mount_point}/; then
echo "Mounting failed! Cannot run backup without the backup mounted!"
exit 1
fi

echo "Preparing to transfer files using rsync"

#Use current year to create new backup directory each year
#current_year='date +%Y'

#Specify mount point followed by the path to the bakup directory, finish with current year
#Would like to add month and date
#backup_path=${mount_point}'/EdensLandCorp/'${current_year}
#echo "Backup directory is ${backup_path}"

echo "starting backup of /Share/*..."
rsync --verbose --progress --stats --compress --recursive --times --perms --links --delete /Share/* /mnt/backup 2>&1 | tee /mnt/backup/elc_backup.txt

but i am not ready to use it yet, as i need to figure out the mount_point in the script. I mount a nas to /mnt/backup and have rsync backup to that mount point. What i would like now is to know how to create a cron job that runs this command, nightly and 7:00pm:

rsync --verbose --progress --stats --compress --recursive --times --perms --links --delete /Share/* /mnt/backup 2>&1 | tee /mnt/backup/elc_backup.txt
Can anyone help me with this?

Jim Henderson
18-Apr-2012, 02:09
On Wed, 18 Apr 2012 01:04:01 +0000, carnold6 wrote:

> What i would like now is to know how to create a cron job that runs this
> command, nightly and 7:00pm

Easiest way would be to create a cron entry using 'crontab -e' as root:

# crontab -e

The format of the crontab lines is documented in 'man 5 crontab' - it's a
fairly straightforward format:

0 19 * * * commandtorunhere -withparameters -likethis

I'd probably put the command to run in a shell script and call the shell
script from crontab instead - you'll want to make sure to use absolute
paths uniformly.

Jim

--
Jim Henderson, CNA6, CDE, CNI, LPIC-1, CLA10, CLP10
Novell Knowledge Partner