LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-13-2010, 08:31 PM   #1
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Rep: Reputation: 32
crontab


Hi all

Can some one give me a sample of a crontab for backing a directory please, System is Ubuntu 9.04

Quote:
#!/bin/bash

# this file is an automated backup script, backup.sh.
# this backs up my domain site.

cd /var/www/
#rm /Downloads/html.bak/htmlbackup.sh.tar.gz
tar -zcf /Downloads/html.bak/htmlbackup.sh.tar.gz .
TT ( karl )
 
Old 09-13-2010, 09:09 PM   #2
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
Note that each time you run that it will overwrite the previous backup. So, you will only ever have one backup. If something gets messed up and you don't notice it until after that script runs, then the messed up thing will be your only backup. So, you want to use a backup file name with a date stamp in the name. For example, you could use

tar -zcf /Downloads/html.bak/htmlbackup-`date +%Y%m%d`.tar.gz .

would result in a filename of htmlbackup-20100913.tar.gz for today. You could clean them out periodically, or build it into your script to remove things older than a week or a month or whatever you choose.

The cron entry to run your script at, say, 1:00am in the morning would be:

0 1 * * * /path/to/your/script

check the man pages for cron and for crontab. `crontab -l` (that is an "el") will show you the contents of your crontab. `crontab -e` will allow you to edit the crontab directly.
 
1 members found this post helpful.
Old 09-13-2010, 09:14 PM   #3
mcd
Member
 
Registered: Aug 2003
Location: Denver, CO
Distribution: CentOS, Debian
Posts: 825

Rep: Reputation: 33
You edit your crontab with this command:

Code:
sudo crontab -e
There are a lot of other references out there that can tell you all the exact syntax, but basically first you say how often you want the job to run, then you say what command should be run.

Code:
45 18 * * * /home/chris/bin/backup.sh
That would run every night at 6:45pm. The first column is minutes, the second hours, third days of the month, fourth is month, and the fifth is day of the week. So

Code:
30 02 * * 2 /home/chris/bin/backup.sh
would run at 2:30am every Tuesday, and

Code:
0 6 1 1 * /home/chris/bin/backup.sh
would run only once a year, at 6:00am on New Years. That script you have should do just fine, although you'll only ever have one backup file at a time. Every time the script runs it will overwrite the old one. If you want a new file each time, you could do this:

Code:
tar czf /Downloads/html.bak/htmlbackup-`date +%Y-%m-%d`.tar.gz .
That will append the date to the end of the filename. Oh, and the usual practice is to use .tar.gz for the file extension, not .sh.tar.gz.
 
Old 09-13-2010, 09:18 PM   #4
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Original Poster
Rep: Reputation: 32
Thanks guys

I'll give it ago and get back to you ASAP

TT ( karl )
 
Old 09-13-2010, 11:03 PM   #5
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Original Poster
Rep: Reputation: 32
The back has to go to another drive on the system, USB external drive ( /dev/sdb1 )

Would it be some thing like so

Code:
tar czf /dev/sdb1/Downloads/html.bak/htmlbackup-`date +%Y-%m-%d`.tar.gz .
TT ( karl )
 
Old 09-14-2010, 04:13 AM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
You need to use the mountpoint
use mount to see.
You could add a line to see if the drive is mounted or not, before backingup.


Kind regards
 
Old 09-15-2010, 08:17 PM   #7
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Original Poster
Rep: Reputation: 32
we got the mount worked out OK

when I run the script

I get the following error

Code:
Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
Any reason why

TT ( karl )
 
Old 09-15-2010, 09:09 PM   #8
basheer
Member
 
Registered: Mar 2009
Location: Bangalore, India
Distribution: CentOS6.5, CentOS7, Ubuntu14.04
Posts: 182

Rep: Reputation: 29
Smile

Quote:
Originally Posted by tommytomato View Post

Would it be some thing like so

Code:
tar czf /dev/sdb1/Downloads/html.bak/htmlbackup-`date +%Y-%m-%d`.tar.gz .
TT ( karl )
Your mount point seems to be wrong here. /dev/sdb1 is mounted on something else.

Check the output of mount -l and see where it is mounted and use that mount point in your tar command instead of /dev/sdb1.

Else post the output of mount -l here.

Best of luck.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux crontab vs unix crontab ytd Linux - General 2 08-09-2009 05:07 AM
replaced crontab, now should get crontab back to what it was raminn Linux - Newbie 2 10-20-2008 07:15 PM
man crontab(5) vs crontab(1) Canis Polaris Linux - Newbie 2 06-04-2008 04:03 PM
Crontab Help cybersteve2005 Linux - Software 3 09-05-2005 12:22 PM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:14 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration