I have been using pax to backup the files in my Unix Services directory and needed to restore a file so I could compare it with the last version ( and work out why my updates didnt work). Unfortunately I managed to overwrite my latest version instead of creating a copy.
I backed up my directory using
pax -W “seqparms=’space=(cyl,(10,10))'” -wzvf “//’COLIN.PAX.PYMQI2′” -x os390 /u/tmp/pymqi2/
This created a data set COLIN.PAX.PYMQI2 with the give space parameters, and os390 format.
To list the contents of this file use
pax -f “//’COLIN.PAX.PYMQI2′”
To display a subset of the files use
pax -f “//’COLIN.PAX.PYMQI2′” /u/tmp/pymqi2/code
And provide more information using the -v option
drwxrwxrwx 1 COLIN 1000 0 Jan 22 17:04 /u/tmp/pymqi2/code/ drwxr-xr-x 1 COLIN 1000 0 Feb 11 13:10 /u/tmp/pymqi2/code/pymqi/ -rw-r--r-- 1 OMVSKERN 1000 133011 Feb 22 13:15 /u/tmp/pymqi2/code/pymqi/init.py -rw-r----- 1 COLIN 1000 119592 Feb 3 12:59 /u/tmp/pymqi2/code/pymqi/old__init__.old -rwx------ 1 OMVSKERN 1000 119565 Jan 22 16:43 /u/tmp/pymqi2/code/pymqi/aa
To restore an individual file and overwrite the original I used the -r option.
pax -rf “//’COLIN.PAX.PYMQI2′” /u/tmp/pymqi2/pymqi/__init__.py
I was expecting the file to be restored relative to the directory I was in; No – because I had backed up the files using an absolute path it restored the file to the same place, and so it overwrote my changes to the file. I had changed to a temporary directory, but I had not realised how the command worked.
There are several ways of doing it properly.
Restore with rename
pax -rf “//’COLIN.PAX.PYMQI2′” -i /u/tmp/pymqi2/pymqi/__init__.py
The -i option means rename.
I ran the command and it prompted me to rename it
Rename “/u/tmp/pymqi2/pymqi/__init__.py” as…
Set “do not overwrite”
I could also have used the -k option which prevents the overwriting of existing files.
Rename on restore
I could also have used the rename
pax -rf “//’COLIN.PAX.PYMQI2′” -s#/u/tmp/pymqi2/pymqi#/tmp/# /u/tmp/pymqi2/pymqi/__init__.py
Where the -s#/u/tmp/pymqi2/pymqi#/tmp/# / says use the regular expression to change /u/tmp/pymqi2/pymqi to /tmp and so restore it to a different place. Note: The more obvious -s/abc/xyz/, where / is used as the delimiter, would not work, as there is a ‘/’ in the file path.
All of the above
I could have use all of the options -i -k -s…. .
A better way to backup.
I had specified an absolute directory /u/tmp/pymi2/. If I was in this directory when I did the backup I could have used
pax … -x os390 .
Where the . at the end means from this directory, and so backup a relative directory.
If I list the files I get
pax -f “//’COLIN.PAX.PYMQI2A'” ./aa
And now if I restore the file…
pax -rf “//’COLIN.PAX.PYMQI2A'” ./aa
It restored the file into my working directory /tmp/aa .
So out of all the good ways of backing up and restoring – I chose the worst one. It only took me about 2 hours to remake all the changes I had lost.