Sponsored Content
Top Forums Shell Programming and Scripting Help Writing File Restore Script Post 302995564 by bashbeginner on Friday 7th of April 2017 04:04:56 PM
Old 04-07-2017
Help Writing File Restore Script

Hi all,

I have been tasked with creating a script that sends a file into a created "recycling" directory and another script that restores a "deleted" file. I have already created the removal script but am stuck on the restoring part.

I need to restore the file to its original location by using its path name, which can be found in the .restore.info file that I created.

Here is the removal script:
Code:
# did the user enter a filename
if [ -z "$1" ]; then
echo "No file was entered"
exit
fi

# warns the user if a directory and not a file was entered
if [ -d "$1" ]; then
echo "Directory name entered. Please enter file name"
exit
fi

# if the correct file name is entered then display file deleted
if [ ! -f "$1" ]; then
echo "$1 Does not exist"
exit
fi

# finds inode of a file to avoid files with the same name
inode=$(stat -c '%i' $1) 2>/dev/null

# shows the path of the file
path=$(readlink -f "$1") 2>/dev/null

# prints name of the file and its path in the .restore.info file
echo "$1_$inode:$path" >> ~/.restore.info 2>/dev/null

# warns the user if they enter this script as an argument
if [ $1 = "remove123" ]; then
read -p "Are you sure you want to delete remove? y/n:  " answer

#if yes, then remove the file otherwise do nothing
if [[ $answer = y ]] ; then
        mv "$1" deleted/"$1"_"$inode" 2>/dev/null
        echo "$1_$inode:$fixedPath" >> ~/.restore.info 2>/dev/null
else
        exit
fi
fi

#moves to deleted dir
mv "$1" deleted/"$1_$inode" | cut -d "  " -f 1 2>/dev/null

So far for my restore script, I have:
Code:
#find the original path of the file
path=$(readlink -f "$1/.restore.info") 2>/dev/null

#move the file back to its original path
mv $1 $path

Please forgive me for my basic language, I'm very new to Unix programming.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

help writing script file

Does anyone know how I can write a script file that reads 15 numbers and can find the average, maximum and minimum of the 15 numbers. I'm new to UNIX 1 month into it, and (no) this is not for homework. I'm reading UNIX unbounded and trying the practice questions and I've been working on... (19 Replies)
Discussion started by: lanboy_2005
19 Replies

2. Shell Programming and Scripting

Writing to a file within a script

Hi, At the moment i have a script where it asks the user if they want to create a file and what to put in the file. The problem is when the script is run the user inputs the information, though when they are finished typing what they want to be in the file there is no way for the program to know... (3 Replies)
Discussion started by: Jaken
3 Replies

3. Shell Programming and Scripting

writing script file for database

how to disable a constraint type of a field (present in diffrent tables) in the database unix a unix script file.. (3 Replies)
Discussion started by: shaksing
3 Replies

4. Shell Programming and Scripting

script for writing to a file

Hi, Can some some give ideas/help how to write to a file. i need to create a calender from the inputs given on command line i.e frm date,todate & -i is interval is given to write to a file. -i is 1 then a calender is daily , if -i =2 then calender is alternate day e.g $1 ... (0 Replies)
Discussion started by: innocent
0 Replies

5. UNIX for Dummies Questions & Answers

Help writing a script to find a file

I just started learning about Unix and I cant figure out what im doing wrong. I'm trying to write a script that will ask for the file name and tell what type it is. This is what i have so far. http://i63.photobucket.com/albums/h123/wacand/untitled.jpg (2 Replies)
Discussion started by: wacand
2 Replies

6. Shell Programming and Scripting

Help with writing shell script file

I am trying to prompt the user using tput command to read the information ( 5 last names, first names and grades) from the keyboard. Save the data in a file called student.txt. Sort the file by last name and display it on the screen My pseudocode is as follow: Pseudocode: Initialize... (1 Reply)
Discussion started by: jestaton
1 Replies

7. Shell Programming and Scripting

Need help in writing a script to edit a file

Hi all, I need help in writing a script to edit a file Here is the sample of my file abc xxx 123 456 789 045 def yyy 987 678 098 cdf zzz 435 543 jhg vvv 987 765 (2 Replies)
Discussion started by: leo.maveriick
2 Replies

8. Shell Programming and Scripting

writing the main script file

Hi, I am new to shell scripting,and i was planning to write a script that will move files which have a datetime >= currentdate-N from a source to destination folder. All configuration should be done through a properties files. Here the value of N should be taken as 10 days(modification... (6 Replies)
Discussion started by: rahul125
6 Replies

9. UNIX for Dummies Questions & Answers

Writing a script that will take the first line from each file and store it in an output file

Hi, I have 1000 files names data1.txt through data1000.txt inside a folder. I want to write a script that will take each first line from the files and write them as output into a new file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

10. Shell Programming and Scripting

Help with rsync file restore script

Hello Friends, I am trying to create an rsync file restore script. I will post want I have below and explain the problem I am having. #!/bin/bash # # Partial Rsync File Restore Script # # clear echo # Shell loads into /raid0/data/backup/bin/ cd .. # I cd to the backup... (1 Reply)
Discussion started by: jdavis_33
1 Replies
restore(8)						      System Manager's Manual							restore(8)

Name
       restore - incremental file system restore

Syntax
       /etc/restore key [ name... ]

Description
       The  command  reads from magnetic tapes, disks, a file, or a pipe created by the command.  The default dump media from which files are read
       is You can request another dump device or dump image file by using the f key modifier.  The key is a character string containing one  func-
       tion  letter  and possibly one or more function modifiers.  Other arguments to the command are file or directory names specifying the files
       to be restored.	Unless the h key is specified, the appearance of a directory name refers to all files and, recursively, the subdirectories
       of that directory.  The function portion of the key is specified by one of the following letters:

Keys
       i    This key allows interactive restoration of files from the dump media.  After reading in the directory information from the dump media,
	    lets the user move around the directory tree selecting or deselecting files to be extracted.  The available interactive commands are:

	    ls [arg]	List the specified directory.  If no directory is specified, the user's current directory is  listed.	Entries  that  are
			directories  are  appended  with a slash (/).  Entries that have been marked for extraction are prepended with an asterisk
			(*).  If the verbose key is set, the inode number of each entry is also listed.

	    cd arg	Change the current working directory to the directory specified.

	     pwd	Print the full pathname of the current working directory.

	    add [arg]	The current directory or the specified argument (a directory or file) is added to the extraction list (the list  of  files
			to  be	extracted).  If a directory is specified, then it and all its descendents are added to the extraction list, unless
			the h key is specified on the command line.  Files that are on the extraction list are prepended with an asterisk (*) when
			they are listed by ls.

	    delete [arg]
			The current directory or specified argument is deleted from the extraction list (the list of files to be extracted).  If a
			directory is specified, then it and all its descendents are deleted from the extraction list, unless the h key modifier is
			specified  on  the command line.  The easiest way to extract most of the files from a directory is to add the directory to
			the extraction list and then delete those files that are not needed.

	    extract	All the files on the extraction list are extracted from the dump media.  The command asks which volume the user wishes	to
			mount.

	    verbose	The  verbose  ( v ) key is toggled.  Entering the command turns on verbose.  Entering the command again turns off verbose.
			When used, the verbose key causes the ls command to list the inode numbers of all entries.  It also causes  to	print  out
			information about each file as it is extracted.

	    help	List a summary of the available commands.

	    quit	The utility immediately exits, even if the extraction list is not empty.

       R    The  utility prompts for a particular volume of a multivolume set on which to restart a full restore.  This option lets be interrupted
	    and then restarted.

       r    The dump media's data is read into the current directory.  You should use this function key only to restore the  complete  dump  media
	    onto  a  newly created file system, or to restore incremental dump media after a full level-0 restore.  See the Examples section for a
	    typical sequence to restore complete dump media.  Note that leaves a file, in the root directory to pass information between incremen-
	    tal  restore  passes.  Remove this file after the last incremental dump media has been restored.  A followed by a and a can be used to
	    change the size of a file system.

       t    The names of the specified files are listed if they occur on the dump media.  If no name argument is given, then the root directory is
	    listed.  This results in the entire contents of the dump media being listed, unless the h key modifier has been specified.

       x    The  files	specified  by the name argument are extracted from the dump media.  If a named file matches a directory whose contents had
	    been written onto the dump media and the h key modifier is not specified, the directory is recursively extracted.  The owner,  modifi-
	    cation  time, and mode are restored, if possible.  If no name argument is given, the root directory is extracted.  This results in the
	    extraction of the entire contents of the dump media unless the h key modifier has been specified.

       You can use any of the following characters in addition to the letter that selects the function desired:

       B    The next argument to is a number giving the size, in 1024-byte blocks, of a fixed-size storage medium, such as diskettes or  removable
	    disks  (see  the Examples section).  The command does not ask whether it should abort the restore if there is a dump media read error.
	    It always tries to skip over the bad block(s) and continue.

       f    The next argument to is used as the name of the archive instead of If the argument is a dash (-), reads from standard input  (see  the
	    Examples section).

       h    The  command  extracts the actual directory, rather than the files that it references.  This prevents hierarchical restoration of com-
	    plete subtrees from the dump media:

       m    The command extracts by inode numbers rather than by file name.  This is useful if only a few files are being extracted, and you  want
	    to avoid typing the complete pathname to the file.

       s    The  next  argument identifies which dump file on the dump media is to be used by This is useful when the dump media has more than one
	    dump image on it and not all of them will be restored.

       v    Normally, does its work silently.  The v (verbose) key modifier causes it to display the name of each file it treats, preceded by  its
	    file type.

Examples
       The following example shows a typical sequence of commands to restore complete dump media.
       /etc/newfs /dev/rra0g ra60
       /etc/mount /dev/ra0g /mnt
       cd /mnt
       restore r
       Another can be done to get an incremental dump.

       The following example shows how and can be used in a pipeline to dump and restore a file system:
       dump 0f - /usr | (cd /mnt; restore xf -)
       The following example shows how to restore files interactively from a dump on RX50 diskettes:
       restore iBf 400 /dev/ra2a

Restrictions
       The utility can make errors when doing incremental restores from dump media that were made on active file systems.

       You  must  do a level 0 dump after a full restore.  Because runs in user code, it has no control over inode allocation; thus, you must do a
       full to get a new set of directories that reflects the new inode numbering, even though the contents of the files are unchanged.

Diagnostics
       Complains about bad key characters.

       Complains if it gets a dump media read error.  If the user responds with a y, attempts to continue the restore.

       If the dump extends over more than one dump volume, will ask the user to change volumes.  If the x or i function key  has  been	specified,
       also asks which volume the user wishes to mount.

       There are numerous consistency checks that can be listed by Most checks are self-explanatory.  Some common errors are:

       Converting to new file system format
       If dump media created from the Fast File System (FFS) has been loaded.  It is automatically converted to the Berkeley Version 4.2 file sys-
       tem format.

       <filename>: not found on tape{disk}
       The specified file name was listed in the dump media directory, but was not found on the media.	This is caused by dump media  read  errors
       while looking for the file or from using dump media created on an active file system.  Expected next file <inumber>, got <inumber>
       A file that was not listed in the directory was found on the media.  This can occur when using dump media created on an active file system.

       Incremental tape{disk} too low
       When  doing incremental restore, dump media was loaded that was written before the previous incremental media or has too low an incremental
       level.

       Incremental tape{disk} too high
       When doing incremental restore, dump media that does not begin its coverage where the previous incremental dump media left off, or that has
       too high an incremental level has been loaded.

       Tape{Disk} read error while restoring <filename>
       Dump media read error while skipping over inode <inumber>
       Dump media read error while trying to resynchronize
       A  dump	media read error has occurred.	If a file name is specified, then its contents are probably partially wrong.  If an inode is being
       skipped or the restore is trying to resynchronize, then no extracted files have been corrupted, although files may not be found on the dump
       media.

       resync restore, skipped <num> blocks
       After a dump media read error, may have to resynchronize itself.  This message lists the number of blocks that were skipped.

Files
       Default tape drive

       File containing directories on the dump media

       Owner, mode, and time stamps for directories

       Information passed between incremental restores

       Required for user interface

See Also
       dump(8), mkfs(8), mount(8), rrestore(8c)

																	restore(8)
All times are GMT -4. The time now is 08:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy