A Recycle Bin for the IFS (Sort Of)
April 23, 2008 Hey, Ted
We inadvertently deleted an IFS file that was created today and therefore was not on the previous night’s backup. What I wouldn’t give for an IFS recycle bin! We can recreate the file, but I wonder, short of backing everything up every minute, if there is anything that I could have done to prepare for such a situation? -Chris My sympathy, Chris. I hate it when that happens. As you point out, the IFS has no recycle bin, but there is a way you can delete a file from a directory without deleting it from disk. I’ll show you the technique and you can decide if and how you will implement it. This technique doesn’t work in all file systems, but it will work in the root system, which I use a lot, and it should work in the QOpenSys system, which I never use. In certain file systems, a file’s real name is not the name it is given when it is created. The real name is a system-assigned name, called an inode. The human-assigned name is implemented as a link, stored in a directory, to the inode. This means that a file may have more than one human-assigned name. These names are called hard links. These links do not have to be in the same directory, but they do have to be in the same file system. Let’s say you have a directory whose files you would like to protect from accidental deletion. Before some rogue person or process gets access to the directory, run a Qshell command like the following: for File in * do ln "$File" "/Recycled/$(date +%Y-%m-%d-%H.%M.%S)-$File" done The effect of this bit of Qshell script is that every file in the directory now has two hard links–one in the current directory and one in a directory called Recycled, which you previously created in the root file system. The hard link in Recycled has a slightly different name. I used command substitution, which begins with a dollar sign and open parenthesis and ends with a close parenthesis, to include the output of the date utility. "/Recycled/$(date +%Y-%m-%d-%H.%M.%S)-$File" The result is that the current date and time become prepended to each file name in the Recycled directory. Therefore, file mydata.dat in the current directory has a name like 2008-03-08-13.40.44-mydata.dat in the Recycled directory. It is important to understand that there is only one file, not two. If you delete file mydata.dat, you will no longer see mydata.dat listed in the current directory. You will be able to create a brand new mydata.dat if you like. The first mydata.dat still exists in /Recycled under the name 2008-03-08-13.40.44-mydata.dat. You have two ways to create hard links. You can use CL’s Add Link (ADDLNK) command, like this: ADDLNK OBJ('/mydir/mydata.dat') NEWLNK('/Recycle/2008-03-01-14.21.22-mydata.dat') LNKTYPE(*HARD) Or you can use Qshell’s ln utility, as in the script fragment I gave above. ln "$File" "/Recycled/$(date +%Y-%m-%d-%H.%M.%S)-$File" BTW, prepend is not an “official” English word, but I like it. It’s not in my dictionary, but maybe someday it will be. –Ted RELATED STORY
|