LinuxQuestions.org
Review your favorite Linux distribution.
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 09-10-2009, 02:40 AM   #1
Kanon
Member
 
Registered: Sep 2004
Location: Norge
Distribution: Debian
Posts: 116

Rep: Reputation: 15
Cron job - chekc files and sync to another disk


From time to time a disk goes bad. And to make things worse it always contains documents that are really needed.
I would like to make a cron job that can check the disk/filesystem and sync the files from one disk to another. Not both ways. I can do the manual job to copy back if/when its needed.

How can I achieve this?

Its a Debian Lenny barbone samba server
 
Old 09-10-2009, 03:25 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Just write a script that perform the operations you usually do manually, maybe adding some control statements, then insert it in the user's crontab with
Code:
crontab -e
"man crontab" and "man 5 crontab" give the general information about crontab and describe the format of the crontab entries, respectively. Before you ask, I can summarize some general rules about crontab jobs:

1. in your script always use full paths for each command. The cron environment is different from what is set-up at user's login (that is you don't have the same environment variables) and PATH is usually limited to /bin:/usr/bin.
2. redirect the standard output and the standard error of the job to a file for easy checking at a later time. If not redirected, take in mind that they are sent to the user's mail by default (check it using the mail command from a terminal).
3. use full paths for every file name inside your script, too. Independently from where the script is placed, when the job starts it acts as if it run from the user's home directory. Full paths avoid confusion.

Quote:
And to make things worse it always contains documents that are really needed.
This suggests that a full and regular backup of sensible data/documents is always welcome! Don't wait for things going bad: better to be prepared.
 
Old 09-10-2009, 06:18 AM   #3
Kanon
Member
 
Registered: Sep 2004
Location: Norge
Distribution: Debian
Posts: 116

Original Poster
Rep: Reputation: 15
Thanks for helping me out. But its the script it self I need help with. What commands can I play with that can check the disk? And how can I get cp to check if there is a change in the file. With a change in the file I mean; that it has been updated and not corrupt.

And I rather not go with a hole backup package. I think this solution wil be less strain on the box an easy to maintain.
 
Old 09-10-2009, 06:28 AM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Take a look at rsync
 
Old 09-10-2009, 07:24 AM   #5
Kanon
Member
 
Registered: Sep 2004
Location: Norge
Distribution: Debian
Posts: 116

Original Poster
Rep: Reputation: 15
Rsync is used to copy files from one computer to another. Since the disk is on the same machine its cp I need. Or so I think.
Is there a way to check the integrity of file(s)? So far the best I found is fsck, but does it only run at bootup? Or can I run it anytime?
 
Old 09-10-2009, 07:28 AM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
In order to run fsck, you need to unmount the filesystem.
You can use rsync to copy files to another partition or drive.
 
Old 09-10-2009, 09:14 AM   #7
Kanon
Member
 
Registered: Sep 2004
Location: Norge
Distribution: Debian
Posts: 116

Original Poster
Rep: Reputation: 15
Hey, that will work. Umount, fsck if all ok then rsync.

Thanks!!
 
Old 09-11-2009, 08:15 AM   #8
Marko Hyvärinen
LQ Newbie
 
Registered: May 2009
Posts: 24

Rep: Reputation: 15
cp -u
works best, imho


Marko
 
  


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 for cleaning files ericli Linux - Newbie 9 05-05-2009 10:30 AM
cron job files vikas027 Linux - General 4 11-12-2008 04:42 AM
Cron job files by date Kumado Linux - General 4 04-26-2006 06:02 PM
Cron job to sync two directories Harimwakairi Programming 3 01-06-2006 12:25 AM
cron job to detect new files rblampain Programming 8 12-28-2005 09:51 AM


All times are GMT -5. The time now is 06:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration