Backing Up Directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Backing Up Directories
# 1  
Old 12-17-2003
Backing Up Directories

Hi Guys,

I'm writing a shell script that presents the user with various options, they select one (numbered 1-9) and it then excecutes the correct code. No problem, but I'm having slight difficulty with one option.

The user can select to backup all the files in the current directory to another directory, but the program must first check to see if the destination directory exists and then if not it must create it before copying the files.

backup) print "Please enter the directory to copy your files to:"
read dir
if [ -f $dir ]; then
mkdir $dir
cp /myhomefolder/* $dir
else
cp /myhomefolder/* $dir
fi;;

This is the code I'm using to take the users chosen directory, see if it exists within the current directory and make it if not then copy the files but it's just not working! It just says that the directory entered is not a directory. I'm a bit of a newbie when it comes to this and I've been trawling through websites and books but I just can't get it to work!

Any thoughts? Thankx
# 2  
Old 12-17-2003
try useing a -d in your if statment.

-d= is a directory

you might even want to do a -w (you have write premissions)

in ksh -f = is a regular file (ie not a directory or other special type of file.

i added a -p in your mkdir so it makes any directorys that would be missing in the $dir variable instead of just the last directory.

so something liek this:

Code:
if [ -d $dir ]; then
cp /myhomefolder/* $dir
else
mkdir -p $dir 
cp /myhomefolder/* $dir
fi;;

# 3  
Old 12-17-2003
Humm, there are a number of problems with this
shell script.

"if [ -f $dir ]" tests that $dir exists and is a regular
file. Use "-d" to test that $dir exists and is a
directory. See the test or [ man page. i.e.
"man test" or "man [".

You also should use the -p option to mkdir to
to create intermediate directories as necessary.
i.e. "mkdir -p $dir".

Another test that should probablly be added is
to ensure that the user actually entered a directory
and did not just hit return. test -n or test -z
will help here.

You also should test that user has permission to
write in the target directory and warm them if they
do not have write permission.

- Finnbarr
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Backing up an entire HD

Are there any recommended methods for Backing up an entire HD? I want to backup my data. I do not care about the OS file. I just want my work, movies, and music. I have about 600 GB of work, movies, and music so a bit worried about fragmentation if I just copy and paste. (1 Reply)
Discussion started by: cokedude
1 Replies

2. Solaris

Backing up Solaris 10 servers

Got 5-6 Solaris 10 servers in remote location - power work being done. At the moment, we just back up the application database that these servers run with the idea that if it all goes wrong we can rebuild and then restore the application. However, requirement is to provide a complete backup... (3 Replies)
Discussion started by: paulfoel
3 Replies

3. Shell Programming and Scripting

Need help in backing up of databases.

Hi Everyone, I am new to DBA stuff. I wonder if anyone can help me. Task is that, I have 10 databases and need to take backups of all the databases using data pump in Unix/Linux, compress them using gzip and use cron to schedule the job twice a day. Appreciate if anyone can help me in... (1 Reply)
Discussion started by: sreepriya0987
1 Replies

4. Solaris

Backing up using fssnap and ufsdump

Hi all! Here's my situation: I need to backup a running system before I can bring it down I've tried performing a ufsdump while it's in multi-user mode but my ufsdump fails because there is too much activity on the system. So I read that I could use fssnap to create a snapshot of (in my... (3 Replies)
Discussion started by: Keepcase
3 Replies

5. AIX

what am i backing up

we are running aix on are server. we would like to start doing online backups, but the software company that we use is not beeing much help on what files we are backing up. is there a command that will tell me what files that we are backing up. they offer a service that would back it up for use,... (3 Replies)
Discussion started by: shane.hankins
3 Replies

6. Solaris

Backing up the system

Hello Mentors, Before anything else I would like to thanks to all expert here especially Pressy as he guided me to recover our server from disk failure. I posted a lot of question from these forum site concerning on how to recover our server and luckly you guys help me. Our server is now up and... (6 Replies)
Discussion started by: eykyn17
6 Replies

7. Solaris

Can usfdump be used for backing up 1 directory?

I know I can use ufsdump to backup a full device, but can I use it to just backup specified directories within the device? If so , how? (The man pages do not mention how to do that). If ufsdump can not do it, what are my choices? Thank you! (5 Replies)
Discussion started by: FredSmith
5 Replies

8. UNIX for Dummies Questions & Answers

backing up the vtoc

Can you backup the vtoc, then restore it if you somehow mess it up? This is solaris 9, x86. (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

9. UNIX for Dummies Questions & Answers

Best practises for backing up

Hi, I'm about to start a regular backup schedule for my Linux system. I need some pointers if I may :) The system is *mainly* used as a personal home computer (it's actually a laptop running SuSE 9.2) although I do host some client material from it being a PHP developer. I know that in... (2 Replies)
Discussion started by: d11wtq
2 Replies

10. UNIX for Dummies Questions & Answers

backing up

Ok I'm trying to backup a HD using ufsdump but no matter what I do it rewinds the tape after the dump. Now the tape isn't full (only 285mb) and I still have 6 more partitions I want to put on this tape. How can I stop the tape from rewinding because I can't think of anything. Also is there any... (4 Replies)
Discussion started by: merlin
4 Replies
Login or Register to Ask a Question