LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to make a scheduled backup using cron file? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-make-a-scheduled-backup-using-cron-file-411751/)

mus1402 02-04-2006 09:42 PM

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.

frob23 02-04-2006 10:18 PM

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.

mus1402 02-04-2006 10:51 PM

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...

frob23 02-04-2006 11:23 PM

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?


All times are GMT -5. The time now is 05:27 PM.