Schedule backup with crontab/tar | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Schedule backup with crontab/tar

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-07-2013
Float Float is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 8 September 2013, 12:39 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old 09-07-2013
edfair edfair is offline
Registered User
 
Join Date: May 2008
Last Activity: 27 November 2014, 11:22 AM EST
Location: Tucker GA
Posts: 168
Thanks: 0
Thanked 14 Times in 14 Posts
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.
Sponsored Links
    #3  
Old 09-08-2013
Float Float is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 8 September 2013, 12:39 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 22 November 2014, 10:54 PM EST
Location: Simplicity
Posts: 2,053
Thanks: 134
Thanked 603 Times in 547 Posts

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

Sponsored Links
    #5  
Old 09-08-2013
edfair edfair is offline
Registered User
 
Join Date: May 2008
Last Activity: 27 November 2014, 11:22 AM EST
Location: Tucker GA
Posts: 168
Thanks: 0
Thanked 14 Times in 14 Posts
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.
Sponsored Links
    #6  
Old 09-08-2013
Float Float is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 8 September 2013, 12:39 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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..
Sponsored Links
    #7  
Old 09-08-2013
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 22 November 2014, 10:54 PM EST
Location: Simplicity
Posts: 2,053
Thanks: 134
Thanked 603 Times in 547 Posts
Quote:
Originally Posted by edfair View Post
...
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..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Crontab schedule sid2013 Shell Programming and Scripting 6 01-22-2013 07:40 AM
How to schedule a script in crontab. shrima.pratima Shell Programming and Scripting 1 09-09-2010 04:42 AM
Schedule a Crontab hanie123 UNIX for Advanced & Expert Users 2 08-12-2010 09:07 AM
Crontab schedule sandy1028 Shell Programming and Scripting 2 06-18-2010 07:28 AM
Crontab schedule dkranes UNIX for Dummies Questions & Answers 3 10-02-2008 11:00 AM



All times are GMT -4. The time now is 10:57 PM.