LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 02-04-2006, 09:42 PM   #1
mus1402
LQ Newbie
 
Registered: Dec 2005
Distribution: Fedora Core 4
Posts: 12

Rep: Reputation: 0
How to make a scheduled backup using cron file?


Im using Fedora Core 4 and Im wondering if anyone know how to make a scheduled backup using cron file?

Please inform me as soon as possible.

Thanks in advance.
 
Old 02-04-2006, 10:18 PM   #2
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: Ubuntu, FreeBSD, NetBSD
Posts: 1,449

Rep: Reputation: 47
Make a script to perform the backup and then call it from your crontab.

Here is an example from my system. I dump the filesystem(s) I want across the network to a fileserver. I use ssh to do this. This example probably will not work for you... it is an example. Either modify it for your site or create a whole new model on for your own needs.

Backup script: dump.sched
Code:
#!/bin/sh

PATH=/sbin:/bin:/usr/bin
FILESYSTEMS="ad0s1g"
LOCATION="/usr/data/dmps"
hostname="foobar"
backuphost="fileserver"
backupuser="backups"

perfdump() {
        for file in $FILESYSTEMS
        do
                DUMPFILE="${LOCATION}/L${LEVEL}.N${NUMBER}.${file}.${hostname}.gz"
                echo "Dumping ${file}: /dev/$file to ${backuphost}:$DUMPFILE"
                dump -${LEVEL}Lau -h 0 -f - /dev/$file | gzip -2 |ssh ${backupuser}@${backuphost} dd of=$DUMPFILE
        done
}

dayofmonth=`date | awk 'BEGIN{FS=" "}{print $3}' -`
if [ dayofmonth = "1" ] ;then
        LEVEL="0"
        NUMBER="0"
else
        case `date | awk 'BEGIN{FS=" "}{print $1}' -` in
                Sat)    LEVEL="9"
                        NUMBER="1"
                        ;;
                Sun)    LEVEL="9"
                        NUMBER="2"
                        ;;
                Mon)    LEVEL="9"
                        NUMBER="3"
                        ;;
                Tue)    LEVEL="9"
                        NUMBER="4"
                        ;;
                Wed)    LEVEL="9"
                        NUMBER="5"
                        ;;
                Thu)    LEVEL="9"
                        NUMBER="6"
                        ;;
                Fri)    LEVEL="5"
                        NUMBER=`dc << END
                                $dayofmonth 1-7/pq
                                END`
                        ;;
                *)      echo "Error: something went wrong with the date!"
                        exit 1
                        ;;
        esac 
fi

perfdump
Crontab entry
Code:
23      4       *       *       *   /root/bin/dump.sched
At 4:23 each morning this script performs the backup for me.

Edit: Wow, it's been a long time since I looked at that script. It could probably be done in a much better manner now. I didn't write it to be the best example of a script -- I just needed something to work.

Last edited by frob23; 02-04-2006 at 10:22 PM.
 
Old 02-04-2006, 10:51 PM   #3
mus1402
LQ Newbie
 
Registered: Dec 2005
Distribution: Fedora Core 4
Posts: 12

Original Poster
Rep: Reputation: 0
Im sorry for asking this. But im a newbie you see, so if you dont mind me asking, where exactly do i have to type
Quote:
Backup script: dump.sched
and
Quote:
Crontab entry
? Is it in the text editor like gEdit? or the terminal?

One more thing, which part of the script exactly that do i have to change?

Sorry if my question seems a lil bit silly to you...
 
Old 02-04-2006, 11:23 PM   #4
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: Ubuntu, FreeBSD, NetBSD
Posts: 1,449

Rep: Reputation: 47
You type the contents of the code-box for dump.sched into a file and save it as dump.sched.

You use "crontab -e" to add the other line to your crontab.

What you need to change depends on how you are doing to perform your backups, to what media, what partitions and filesystems, and according to what schedule.

The above script dumps one freebsd partition across a network onto a fileserver. It does a complete backup once a month. A weekly backup each Friday (everything which changed during the week). And a nightly backup every day (but Friday and the 1st of the month) which backs up everything which changed in the last 24 hours.

This is probably a more complex backup schedule than you need and would want to deal with in a restore situation. It is impossible for me to guess what your backup needs are.

What do you need to backup?
What method do you prefer to backup everything?
How often do you want to back things up?
Where are you backing things up to?
 
  


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 - doesn't seem to run scheduled tasks robintw Linux - General 11 11-25-2005 01:53 AM
What does cron do if machine is down when job is scheduled? Utah Linux - Software 4 08-24-2005 07:23 PM
creating a cron(tab) scheduled thing student04 Linux - Software 5 12-26-2004 09:18 PM
is there anyway to make linux turn on at a scheduled time? jontyrhodes Linux - General 2 06-04-2004 01:04 PM
Can I make a Cron job to synch/transfer a file from a folder to another FTP?... read efishta Linux - General 6 07-19-2003 10:03 PM


All times are GMT -5. The time now is 11:56 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration