Restoring a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Restoring a file
# 1  
Old 11-09-2005
Data Restoring a file

I'm new to Unix and have just wrote a little program to move files to a recycle bin (a Directory i created) and restore them. The problem is that i need to keep track of all the full filenames so that i can restore them to the right place. I did this by creating a file called delreg and putting the full filenames in it.
But i don't know how to write the full filename to the file or for that matter how to restore the file. My code so far looks like this
pwd >> /home/zoolz/delreg
$1 >> /home/zoolz/delreg
But this code only puts it on 2 lines.
Please if anyone can help it would be great because i seem to be banging my head against a wall
# 2  
Old 11-10-2005
Not sure if I understood your problem?! Give example. How do you identify the files that will move to the bin?
nimo
# 3  
Old 11-10-2005
Not sure about you requirements, but are you taking care of these things:

(a) the recycle bin should ideally be able to store multiple files with same names (see the RecycleBin on Windows)

(b) If I understand right you are trying to store "pwd" as the location where the file will be finally restored. Careful here, because while using the rm command I can specify a pathname myself. i.e. being in the directory "/home" I can delete a file like this "rm /home/user10/testfile.txt". Obviously you dont want to restore testfile.txt to "/home"
# 4  
Old 11-10-2005
Quote:
Originally Posted by zoolz
I'm new to Unix and have just wrote a little program to move files to a recycle bin (a Directory i created) and restore them. The problem is that i need to keep track of all the full filenames so that i can restore them to the right place. I did this by creating a file called delreg and putting the full filenames in it.
But i don't know how to write the full filename to the file or for that matter how to restore the file. My code so far looks like this
pwd >> /home/zoolz/delreg
$1 >> /home/zoolz/delreg
But this code only puts it on 2 lines.
Please if anyone can help it would be great because i seem to be banging my head against a wall
Check this out.

This will put the filename into a hidden file.

Code:
#! /bin/ksh
# ./delreg file

[ -z "$1" ] && echo "Need a file to delete" && exit 1 || FILE="$1"

# delreg is in the directory DIRNAME
DIRNAME=`pwd`

#  FILE will ibe either one of the following
#+ DIRNAME/FILE
#+ or /FILE
#+ //FILE will evaluate to /FILE

if [ -f "$DIRNAME/$FILE" ] ; then
echo "$FILE@@$DIRNAME/$FILE" >> /tmp/.delreg.list
#mv $FILE /tmp
exit 0
fi ;

if [ -f "/$FILE" ] ; then
echo "$FILE@@/$FILE" >> /tmp/.delreg.list
#mv "/$FILE" /tmp
exit 0
fi ;
echo "$1 is not a valid file"

Code:
[~/temp]$ ./delreg.ksh /etc/passwd
[~/temp]$ ./delreg.ksh /etc/pass
/etc/pass is not a valid file
[~/temp]$ ./delreg.ksh /etc
/etc is not a valid file
[~/temp]$ ./delreg.ksh delreg.ksh


Code:
[~/temp]$ cat /tmp/.delreg.list 
/etc/passwd@@//etc/passwd
delreg.ksh@@/home/vino/temp/delreg.ksh

The @@ is delimiter. The pattern goes as $FILENAME@@$LOCATION

This script does the delete part. You will have to extend on this script to recycle the file.

I dont know the behaviour of
Code:
./delreg.ksh delreg.ksh

I think it should move itself to /tmp

Uncomment the # in front of the mv statement.

vino
# 5  
Old 11-11-2005
Computer

Thanx guys that got me out of a jam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

CentOS7 restoring file capabilities

Quite an obscure question I think. We have a rebuild process for remote sites that allows us to PXE rebuild a till (actually a PC with a touch screen and various fancy bits) running CentOS. The current CentOS5 tills work just fine with a tar image restore and some personalisation. Sadly,... (4 Replies)
Discussion started by: rbatte1
4 Replies

2. UNIX for Dummies Questions & Answers

Restoring deleted file with rm -rf

Is there a way I could recover a deleted text file with "rm -rf" command. Running CentOS 6.5. Thank you. (5 Replies)
Discussion started by: galford
5 Replies

3. Shell Programming and Scripting

Restoring a file to its original location

Hello everyone, I am attempting to make a recycling bin type application in shell script (tcsh). I have the whole part of the application done where someone can recycle files from one location to the recycling bin (the lower half of the program), this is not a problem. However I wanted to make... (7 Replies)
Discussion started by: tastybrownies
7 Replies

4. Red Hat

Issues restoring a large dump file

Post deleted. (0 Replies)
Discussion started by: Nobody_knows_me
0 Replies

5. Shell Programming and Scripting

restoring file to its default location...

Hello everyone, I am new to unix shell. I have a file called Path.txt....and i have data in that as 1 abhi 2 avi 3 ash so on..... 1 ,2 ,3 is the... (2 Replies)
Discussion started by: AbhijitIT
2 Replies

6. UNIX for Dummies Questions & Answers

Restoring back a deleted file in unix.

Hi, Can any one tell me how to restore back the deleted file in unix? I know the file name. If i know the inode number of the file does help more to restore back the file? (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

7. UNIX for Dummies Questions & Answers

Blocksize problem restoring file from tape

I was recently given the responsibility of the unix box at our work. Without much training, I now have to go back and restore a file from tape. I'm having some trouble with it. I'm getting an error with the blocksize. The part of the script that does the tar looks like this: tar cvfX... (11 Replies)
Discussion started by: citrowske
11 Replies

8. Solaris

Restoring TAR'd file to different location

Is it possible to restore a TAR'ed file off of a tape to a location other than the original location? If so, how? (The MAN pages give examples of how to restore only to the originating location.) Thanks!! (1 Reply)
Discussion started by: FredSmith
1 Replies

9. UNIX for Dummies Questions & Answers

Restoring a single file...???

Can anyone please help...? Managed to do a ufsdump of files to tape. Having trouble using ufsrestore to pull a single file back by filename?? I have dumped a single file to tape also because looking through the other threads, I noticed that you have to tell it to skip files before you get to... (1 Reply)
Discussion started by: Jonathan
1 Replies

10. UNIX for Dummies Questions & Answers

Restoring a file from Tape

help please i have "inherited" a Sco Server (the administrator departed in a hurry...yes we are chasing him..) and haven't used Unix for 8 years. i have a file that i need to retrieve from a tape. i have been able to find the file on tape using the cpio -ivt command. however... the problem I... (3 Replies)
Discussion started by: mfischer
3 Replies
Login or Register to Ask a Question

Featured Tech Videos