LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cron Job Question (https://www.linuxquestions.org/questions/linux-newbie-8/cron-job-question-456670/)

tarballed 06-20-2006 02:44 PM

Cron Job Question
 
Rather simple really, but wanted to get some feedback here.

I need to create a cronjob that runs nightly and backups up certain directories. I was going to place it in my /home partition for now, until I can copy it to another location.

Few questions:

This cronjob will need to run nightly.
Secondly, will it overwrite the previous nights backup if I don't specifically cut/move the day before?

Lastly, would it be best to use a script to do my job? I basically need to backup one big directory and figured I would just use tar; like so:

tar -czf /home/tarballed/backup.tar.gz /path/to/location


The cronjob (which I was going to setup with a user who has complete sudo access: would be:

crontab -e

0 2 * * * tar -czf /home/tarballed/backup.tar.gz /path/to/location

That way, it would run every night at 2am?

How would I exclude Saturday and Sunday?
Is it ok to just specifiy the command like above? Or would it be better to put it in a simple sscript?

Just looking for some feedback/recommendations/changes to this.

J_K9 06-20-2006 03:07 PM

Hi,

I think it'd be easier to write a script like the following:
Code:

#!/bin/bash
# Backup Script
PATH=/bin:/usr/bin
BACKUPDIR=/backup/daily
DIRTOBACKUP=/home
TODAY=`date +%d%b%y`
mkdir /$BACKUPDIR/$TODAY
tar -czf $BACKUPDIR/$TODAY/backup.tgz $DIRTOBACKUP

I'm a bash scripting newbie... But that script should work - just make sure you change the DIRTOBACKUP value, as it is currently set to /home, which is the directory which will be backed up in this case.

I recommend you set this script to run using crontab. For a quick tutorial which should teach you what you want to do, read this: http://www.tech-geeks.org/contrib/md...ntab-howto.htm

Cheers,

-jk ;)

brazilian_user 06-20-2006 03:29 PM

This command will overwrite your previous backup, what you need to do is create a script and put it in the crontab.

For example:

0 2 * * 1-5 root /home/my/script

I think this solve your problem.

J_K9 06-20-2006 03:35 PM

Quote:

Originally Posted by brazilian_user
This command will overwrite your previous backup

Precisely - which is why I posted that script. The script will add a new backup every day, and add the date to the directory so that each backup is unique and does not overwrite previous ones.

However, in this case, you will need to watch out with the increasing number of backups.. As I have not put anything in the script to delete backups which are x days old ;)

brazilian_user 06-20-2006 03:39 PM

Quote:

Originally Posted by J_K9
Precisely - which is why I posted that script. The script will add a new backup every day, and add the date to the directory so that each backup is unique and does not overwrite previous ones.

However, in this case, you will need to watch out with the increasing number of backups.. As I have not put anything in the script to delete backups which are x days old ;)


Perfectly :)


All times are GMT -5. The time now is 12:21 AM.