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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-20-2006, 02:44 PM
|
#1
|
|
Member
Registered: Jun 2002
Distribution: RH, FC, FreeBSD,OpenBSD
Posts: 326
Rep:
|
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.
|
|
|
|
06-20-2006, 03:07 PM
|
#2
|
|
Member
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700
Rep:
|
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 
|
|
|
|
06-20-2006, 03:29 PM
|
#3
|
|
Member
Registered: Nov 2005
Location: Brazil, Poá - São Paulo
Distribution: Debian Etch
Posts: 110
Rep:
|
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.
|
|
|
|
06-20-2006, 03:35 PM
|
#4
|
|
Member
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700
Rep:
|
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 
|
|
|
|
06-20-2006, 03:39 PM
|
#5
|
|
Member
Registered: Nov 2005
Location: Brazil, Poá - São Paulo
Distribution: Debian Etch
Posts: 110
Rep:
|
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 
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:38 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|