LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Script programing (https://www.linuxquestions.org/questions/programming-9/script-programing-121738/)

agallant 12-01-2003 05:23 PM

Script programing
 
Ok I have a programming question.

I have 2 hard drives in my box which acts as a server. The first hard drive is running redhat 9 the 2nd has nothing on it. I want to write a script that will once a day make a folder on HD2 name it today’s date and copy all information from /home on it. Any ideas? Just a bit of background on this. The server is at a clients and they don’t want to pay for RAD or any kind of tape drive.

-AG

LogicG8 12-01-2003 05:54 PM

you could run something like this as cron job

Code:

#/bin/sh

cd /mnt/backup_drive
NEWDIR=`date +%d_%m_%g`
mkdir $NEWDIR
cp -pa /home/* $NEWDIR/


lyle_s 12-01-2003 08:00 PM

One minor note: use:
Code:

date -I
so the directories sort chronologically.

Lyle

cludwin 12-01-2003 08:01 PM

Have you considered CVS?
It would save a ton of space by saving the changes rather than saving the entire directory structure each night?

agallant 12-01-2003 08:06 PM

I am sorry guys i was not quite as clear on this as i should have been. On top of copying /home into a backup directory on HD2 i would like it to have the old directorys deleted every 2 weeks. This way i can go back 2 weeks incase some one accadently saved changes to a file that they did not want to or some thing like that.

lyle_s 12-01-2003 10:08 PM

Here's something you can try. Be very careful with it because it uses rm -Rf at one point.

Code:

#!/bin/bash

#set -x

BACKUP_DIR=/home/lyle/empty/backups

DELETE_AFTER_DAYS=14

(
        if ! cd "$BACKUP_DIR" &> /dev/null
        then
                echo Could not change to $BACKUP_DIR.  Exiting.
                exit 1
        fi

        find -daystart -maxdepth 1 -type d -ctime +$DELETE_AFTER_DAYS -exec rm -Rf {} \;
)

I tested it with mtime in place of ctime in the find line because that's the only way I could test it short of creating one directory a day for 20 days and then testing it. I don't see a way to change the status change time with touch.

I use rdiff-backup; see http://rdiff-backup.stanford.edu/. I have a year's worth of backups. My home directory (today) is 1.2GB, one years worth of backups is 4.3GB, so it's pretty effecient disk-space wise. I'd recommend using that instead of the above script.

Lyle

agallant 12-01-2003 10:12 PM

Thanks, Lyle. I will give it a try and let you know how it worked.

-AG


All times are GMT -5. The time now is 09:24 AM.