LinuxQuestions.org
Help answer threads with 0 replies.
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 03-08-2006, 04:44 AM   #1
mclard
LQ Newbie
 
Registered: Dec 2004
Posts: 10

Rep: Reputation: 0
Using Cron


Is there a way using cron i could backup the /var/named folder and /etc/named.conf file to a tar file but have it create a daily backup ie. named.monday.tar which would be overwritten the following week.

Sorry if its a bit vague..
 
Old 03-08-2006, 05:44 AM   #2
kevkim55
Member
 
Registered: Dec 2005
Location: Edmonton
Distribution: BLFS, Gentoo
Posts: 353

Rep: Reputation: 32
I think this should be straight forward, yeh ? Write a shell script to do exactly what you want to do and insert an appropriate line into crontab file and cron should execute the shell script at the time you've configured it to. Am I sounding stupid here ?&*^*&^*&
 
Old 03-08-2006, 05:57 AM   #3
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
to create a cronjob, type crontab -e and set it to run at the appropriate time:
* 6 * * * $HOME/script.sh >> $HOME/script.out 2>&1
This should run the script every minute for the 6 AM hour of everyday. The fields are minute, hour, day, month, day of week. See man crontab. The 2>&1 should output both errors and STDOUT.

http://wiki.linuxquestions.org/wiki/Crontab
http://bookmarks.linuxquestions.org/linux?like=cron
 
Old 03-08-2006, 06:33 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
To retrieve the name of the day, use something like:
Code:
today=`date +%A`
(days like "Sunday", "Monday", etc).
or
Code:
today=`date +%a`
(for days like "Sun", "Mon", etc)

Alternatively, you could create backups with full dates in the filenames. This allows you to store
more backups that just one week's worth.
For that, you can use:
Code:
today=`date +%Y%m%d`
In your shell script, you first put that command and then the tar command, using ${today} where you want to put the date in the name of the tar-file.
 
Old 03-08-2006, 07:04 AM   #5
mclard
LQ Newbie
 
Registered: Dec 2004
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks for the quick responses...
 
Old 03-08-2006, 07:16 AM   #6
_KDF
Member
 
Registered: Oct 2003
Distribution: FC4/5 & RHEL4
Posts: 133

Rep: Reputation: 15
I hate shell, so I wrote this quickly using php and run it via cron

Its not perfect and it doesnt do much error chekcing yet but I only wrote it 10 minutes ago so any improvements/critcism welcome !

Code:
#/usr/bin/php
# Simple System backup script - cmcewan 08032006
<?
$backup_dirs = array('etc', 'home', 'root', 'var');  // root directories to be backed up
$backup_target = "/path/to/target";
$host_to_ping = "1.2.3.4" ; // Networked storage server IP


$ping_check = shell_exec("ping -c2 -w2 $host_to_ping") ;
if(strpos($ping_check, '0 received')) {
  echo "Server is offline, stopping backup procedure.....\n";
  echo "Sending alert to sysadmin";
  exit;

# Still to code Mail template, script just exits for just now.

}
else {
# Start the Backup
 shell_exec("rm -rf *.tar ".$backup_target);  // delete old backups

 echo "******* NETWORK STORAGE OK ********\n";
 echo "******* PHP BACKUP STARTED ********\n";

$a = '0'; $b = count($backup_dirs);
$now = date("dmY");

while ($a <= $b) {
echo "Archiving /" . $backup_dirs[$a] . "\n";
shell_exec("tar -cf ". $backup_target . $now."-".$backup_dirs[$a].".tar /" . $backup_dirs[$a]);
  $a++;
} 

echo "";
echo "*******  PHP BACKUP ENDED  ********\n";

}
?>

Last edited by _KDF; 03-08-2006 at 07:18 AM.
 
  


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
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
cron.allow and cron.deny in slackware? tl64 Slackware 5 10-13-2005 09:44 PM
No More Cron Mail, Cron Error? Xhost Linux - General 3 07-26-2004 04:28 PM
[cron][mdk9.1]cron deamon seems to ignore some task... yannrichet Linux - Newbie 5 06-26-2003 09:57 AM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 02:30 PM


All times are GMT -5. The time now is 06:46 AM.

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