Schedule backup with crontab/tar


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Schedule backup with crontab/tar
# 1  
Old 09-07-2013
Schedule backup with crontab/tar

Hello all, I am a complete newbie to Unix and therefor also to this forum. I have an assignment for Uni, and need your help to understand something.

I need to use crontab and tar to schedule a weekly backup of a folder and its contents. I want the tarball to be stored in the users/float directory. The folder name is Important, and is found in /users/float.

Code:
Float@Float-Laptop /cygdrive/c/users/float
$ crontab -e
no crontab for Float - using an empty one
crontab: installing new crontab

Float@Float-Laptop /cygdrive/c/users/float
$ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.q7dIlq7ckg installed on Sat Sep  7 15:42:49 2013)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
45 15 * * 6 tar cvf Important.tar Important

I expected "Important.tar" to show up in users/float at 15.45 Today, but it didn't. Why? I am using Cygwin on my laptop which runs Windows 7.

Last edited by Scott; 09-08-2013 at 08:26 AM.. Reason: Code tags for quote tags
# 2  
Old 09-07-2013
In a different OS I used:
Code:
45 15 * * 6 /usr/bin/backup

and in /usr/bin/backup
Code:
rm usr/float/important.tar
tar cvf /usr/tmp/important.tar /usr/float
mv /usr/tmp/important.tar /usr/float

if I understand what you are attempting.
# 3  
Old 09-08-2013
I think I might have misunderstood something fundamental about the syntax. Just entering
Code:
tar cvf important.tar important

gave me the tar file, and I read somewhere that using crontab will let you schedule any command by simply adding the schedule times before the command.

You've lost me. usr/bin/backup - is this a file you have created, and given it the code that you typed out? What kind of file is this? And is it necessary to give the path like you did, if it is in the same directory as the folder I want to be backed up? Can I do this with cronbar:

Code:
45 18 * * 6 /runthis

and then make a runthis.txt file with code:

Code:
rm important.tar
tar cvf important.tar important

to make it work?

---------- Post updated 08-09-13 at 01:04 PM ---------- Previous update was 07-09-13 at 06:43 PM ----------

My previous post only explains that I've got no idea what I'm doing. It is most helpful if you ignore it, and answer this:

How do I add the code to usr/bin/tar.exe?
I did ls -l in usr/bin and there is no backup but there is a tar.exe in there.
# 4  
Old 09-08-2013
Code:
45 15 * * 6 tar cf Important.tar Important

should work: create important.tar every Saturday at 15:45.
The v option is not needed.
Does the command work outside cron i.e. when run from the command line?
Code:
cd; tar cf Important.tar Important

# 5  
Old 09-08-2013
as you say, entering the tar command as described creates the backup

then you use cron to call a script (you create it) that runs the command (/usr/bin/backup) or whatever else you want to call it or put it.

the rest of the example was used to 1) remove the previous backup so you are not archiving an archive and 2) not to archive a piece of an archive you are creating.

I understood that you were proposing saving the tarball in the same directory that you were tarring.
# 6  
Old 09-08-2013
I just did this
Code:
Float@Float-Laptop /cygdrive/c/users/eirik
$ crontab -e
no crontab for Float - using an empty one
crontab: installing new crontab

Float@Float-Laptop /cygdrive/c/users/eirik
$ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.nuaNGRIUgE installed on Sun Sep  8 17:11:48 2013)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
15 17 * * 7 tar cf important.tar important

and had no result. If this really is supposed to work, then I suspect that my terminal (Cygwin) might be bugged. Whenever I open crontab -e, I have to mash the keyboard for a bit before what I type comes visible, and if I try to paste code, then only the latter part of the code will be pasted. For example, when pasting
Code:
45 15 * * 6 tar cf Important.tar Important

What shows up is
Code:
mportant.tar Important

and there is a red alert in the bottom saying
Code:
E348: No string under cursor

Also, only occosionally when I push the Escape button I get to go on to type :wq to exit crontab -e. Usually when I press Esc, the code will just copy/paste itself some 20-30 times instead. There's also some other strange stuff going on, like when I use the arrow keys; sometimes it makes the "cursor" - the line that shows where I type - move, like it should, and other times it makes the letter A,B,C and D appear on the line above or below the code. This doesn't make much sense to me, but eventually I always get the code I want and I'm able to leave crontab, like now. As you can see, the code is as it should be. but maybe there's some invisible strange stuff going on here, messing up my crontab/tar scheme?

Last edited by Float; 09-08-2013 at 12:48 PM..
# 7  
Old 09-08-2013
Quote:
Originally Posted by edfair
...
I understood that you were proposing saving the tarball in the same directory that you were tarring.
And I understood there is no such problem: directory /cygdrive/c/users/float/Important/ backed up to the separate file /cygdrive/c/users/float/Important.tar
And the tar command directly run from cron - quite okay.

---------- Post updated at 10:56 AM ---------- Previous update was at 10:31 AM ----------

You obviously are struggling with a kind of vi editor.
It has got two modes. It starts in command mode, where cursor keys work and commands like :wq can be done. With the i key you enter the insert mode. With the Esc key you return to command mode.
More help:
Code:
man vi

Or google for: vi quick reference

Last edited by MadeInGermany; 09-08-2013 at 12:39 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to schedule crontab?

Hi All, How to schedule crontab on all day except sunday and monday means from tuesday to saturday at 06:00AM. (3 Replies)
Discussion started by: Riverstone
3 Replies

2. Shell Programming and Scripting

Crontab schedule

Hi all, I would like to schedule a crontab script, which should run From 8pm Thursday to 2am Friday and it should run every 10 minutes. I have put a script like below, is it the correct one. 10 01,02,20,21,22,23,00 * * 4-5 /u01/app/test.ksh Any other options available to schedule the same... (6 Replies)
Discussion started by: sid2013
6 Replies

3. Shell Programming and Scripting

How to schedule a script in crontab.

Hi, My script is in $home/bin/sample.sh. I want to run the script for 3times a day, first execution will be at 08:00 am. second execution will be at 16:00 pm third will be at 23:59 pm. what will be the entry with this requirement?? (1 Reply)
Discussion started by: shrima.pratima
1 Replies

4. UNIX for Advanced & Expert Users

Schedule a Crontab

All, I'm a newbie with crontab and I need your help with schedule a cold-backup running every Sunday at 7am except 1st of the month. Thank you so much. (2 Replies)
Discussion started by: hanie123
2 Replies

5. Shell Programming and Scripting

Crontab schedule

Hi, I have a script which will query the DB and added to crontab at 1,2,6,7 AM everyday and sends a email if count is 0. Now the problem is, if crontab is disabled it doesn't sends a mail. Please tell me how can I handle this situation in the script. (2 Replies)
Discussion started by: sandy1028
2 Replies

6. Shell Programming and Scripting

Unix Crontab schedule

Hi, I want schedule a script with fowllowing days. The crontab and schedule to run every 2 hours from Monday to Saturday at noon. (1 Reply)
Discussion started by: koti_rama
1 Replies

7. Shell Programming and Scripting

Schedule a job using Crontab

I would like to execute my script at 17.30 and 23.00 using crontab, could anybody help me out!! Thanks in Advance!! (1 Reply)
Discussion started by: jatanig
1 Replies

8. Shell Programming and Scripting

How to schedule my script without crontab

I have a script which shoud run after every 30 minutes.Though I know abt crontab, unfortunately I dont have access/authorization to use crontab in my terminal. Could any one pls let me know how to schedule the script without crontab ? Regards Prashant:) (3 Replies)
Discussion started by: prashant43
3 Replies

9. UNIX for Dummies Questions & Answers

Crontab schedule

I have the following crontab entry. 0,30 00-16 * * * This job runs every 30 minutes between the hours of 12:00AM and 4:00PM. How can I have it stop at 4:30PM instead? Thank you, David (3 Replies)
Discussion started by: dkranes
3 Replies

10. UNIX for Dummies Questions & Answers

crontab schedule - first thursday of every month

Instead of the first five fields, one of eight special strings may appear: string meaning ------ ------- @reboot Run once, at startup. @yearly Run once a year, "0 0 1 1 *". @annually (same as @yearly) @monthly Run once a month, "0 0 1 * *". @weekly Run once... (2 Replies)
Discussion started by: paulds
2 Replies
Login or Register to Ask a Question