LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-01-2003, 05:23 PM   #1
agallant
Member
 
Registered: Oct 2003
Location: D.C USA
Distribution: Redhat 9. Thinking about Slackware
Posts: 166

Rep: Reputation: 30
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
 
Old 12-01-2003, 05:54 PM   #2
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
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/
 
Old 12-01-2003, 08:00 PM   #3
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 392

Rep: Reputation: 55
One minor note: use:
Code:
date -I
so the directories sort chronologically.

Lyle
 
Old 12-01-2003, 08:01 PM   #4
cludwin
Member
 
Registered: Feb 2002
Distribution: Slack
Posts: 50

Rep: Reputation: 16
Have you considered CVS?
It would save a ton of space by saving the changes rather than saving the entire directory structure each night?
 
Old 12-01-2003, 08:06 PM   #5
agallant
Member
 
Registered: Oct 2003
Location: D.C USA
Distribution: Redhat 9. Thinking about Slackware
Posts: 166

Original Poster
Rep: Reputation: 30
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.
 
Old 12-01-2003, 10:08 PM   #6
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 392

Rep: Reputation: 55
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
 
Old 12-01-2003, 10:12 PM   #7
agallant
Member
 
Registered: Oct 2003
Location: D.C USA
Distribution: Redhat 9. Thinking about Slackware
Posts: 166

Original Poster
Rep: Reputation: 30
Thanks, Lyle. I will give it a try and let you know how it worked.

-AG
 
  


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
bash programing Paxmaster Programming 1 08-23-2005 06:09 PM
Getting Started with Programing dosnlinux Linux - Software 5 04-29-2005 03:28 PM
Programing in Linux jimbob1989 Programming 1 10-10-2004 10:53 AM
ok so I want to learn some programing Lindy Programming 5 01-01-2004 03:40 PM
Java programing VincentB Linux - Software 3 07-14-2003 07:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:00 PM.

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
Open Source Consulting | Domain Registration