Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-08-2006, 04:44 AM   #1
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
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
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
to create a cronjob, type crontab -e and set it to run at the appropriate time:
* 6 * * * $HOME/ >> $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.
Old 03-08-2006, 06:33 AM   #4
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:
today=`date +%A`
(days like "Sunday", "Monday", etc).
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:
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
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
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 !

# 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 = "" ; // 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";

# 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]);

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


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


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:05 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration