LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-20-2006, 02:44 PM   #1
tarballed
Member
 
Registered: Jun 2002
Distribution: RH, FC, FreeBSD,OpenBSD
Posts: 326

Rep: Reputation: 30
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.
 
Old 06-20-2006, 03:07 PM   #2
J_K9
Member
 
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700

Rep: Reputation: 30
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
 
Old 06-20-2006, 03:29 PM   #3
brazilian_user
Member
 
Registered: Nov 2005
Location: Brazil, Po - So Paulo
Distribution: Debian Etch
Posts: 110

Rep: Reputation: 15
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.
 
Old 06-20-2006, 03:35 PM   #4
J_K9
Member
 
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700

Rep: Reputation: 30
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
 
Old 06-20-2006, 03:39 PM   #5
brazilian_user
Member
 
Registered: Nov 2005
Location: Brazil, Po - So Paulo
Distribution: Debian Etch
Posts: 110

Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Job newbie_adm Linux - Newbie 2 06-05-2006 11:52 PM
Cron Job Question abhijeetudas Linux - Software 2 03-01-2006 11:27 PM
need help with cron job parthcorp1 Linux - General 2 02-01-2005 11:37 AM
Quick Question about cron job andy18 Linux - General 2 08-11-2003 04:16 PM
Cron job T-Rex Linux - Newbie 1 09-26-2001 11:28 AM


All times are GMT -5. The time now is 07:06 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration