Troubleshooting
Problem
This document contains a QShell script to compress and uncompress save files by using the jar tool.
Resolving The Problem
The attached QShell script can be used to compress and uncompress IBM i save files. The compression is really not much better than you get by specifying high data compression on the save file itself but can still be useful to compress existing save files. The script creates a jar (Java archive) file that can be copied through a network drive or binary ftp to the target. It is not necessary to create the save file in advance when using this tool to restore the save file from the jar file. The syntax to use the command is simple and can be displayed simply by typing the name of the script, zip.
To compress a save file, specify the 'c' (compress) option to compress, the name of the jar file that will be created, and the name of the save file in Library/File name format. For example:
zip c myjar qgpl/mysavf
zip c /mydirectory/myjarfile alib/asavf
zip c ./subdirectory1/jarfile1.jar qusrsys/qsavf
To restore a save file from a jar file use the 'r' (restore) option to restore the save file. The save file does not need to be created prior to using the script. The script will restore the save file to the location that it was saved from. There is no option to allow a change in library or file name. Some examples:
zip r myjar
zip r /mydirectory/myjarfile
zip r ./subdirectory1/jarfile1.jar
To display the contents of a jar file, use the 'd' (display) option. This will not restore the files from the jar file; however, it will simply display the contents of the jar file to the screen.
zip d myjar
The zip script is located below and can be copied to Notepad or other text editor and saved to an operating system directory using a network drive or ftp. Then, it can be ran from the QShell prompt. It is designed for interactive use rather than batch. However, as a script, it can be easily modified to suit your own purposes. Lastly, you can download the shell script using the following URL: http://public.dhe.ibm.com/services/us/igsc/cs2/shellScripts/zip
To compress a save file, specify the 'c' (compress) option to compress, the name of the jar file that will be created, and the name of the save file in Library/File name format. For example:
zip c myjar qgpl/mysavf
zip c /mydirectory/myjarfile alib/asavf
zip c ./subdirectory1/jarfile1.jar qusrsys/qsavf
To restore a save file from a jar file use the 'r' (restore) option to restore the save file. The save file does not need to be created prior to using the script. The script will restore the save file to the location that it was saved from. There is no option to allow a change in library or file name. Some examples:
zip r myjar
zip r /mydirectory/myjarfile
zip r ./subdirectory1/jarfile1.jar
To display the contents of a jar file, use the 'd' (display) option. This will not restore the files from the jar file; however, it will simply display the contents of the jar file to the screen.
zip d myjar
The zip script is located below and can be copied to Notepad or other text editor and saved to an operating system directory using a network drive or ftp. Then, it can be ran from the QShell prompt. It is designed for interactive use rather than batch. However, as a script, it can be easily modified to suit your own purposes. Lastly, you can download the shell script using the following URL: http://public.dhe.ibm.com/services/us/igsc/cs2/shellScripts/zip
# zip - a Qshell script to compress and restore iSeries save files
# Written by Michael Swenson
# Check for validity of parameter one, it must be a c to compress or r to restore
# At the same time, check the number of parameters and display usage info if there are
# too few or too many parameters.
declare -u FUNCTION="$1"
if [[ $FUNCTION == C && $# == 3 ]] ; then echo Compressing... ; declare -i VALID1=1 ; fi
if [[ $FUNCTION == R && $# == 2 ]] ; then echo Restoring... ; declare -i VALID1=1 ; fi
if [[ $FUNCTION == D && $# == 2 ]] ; then echo Displaying... ; declare -i VALID1=1 ; fi
if [ ${VALID1:-0} -ne 1 ]
then
echo
echo "Usage: zip {c|r|d} zipfile [LIBRARY/FILE] "
echo "Options: "
echo " -c create a new zipfile (jar file)"
echo " -r restore the contents of zipfile (jar file)"
echo " -d display the contents of zipfile (jar file)"
echo
echo " Example 1: to compress a save file, QGPL/MYSAVF into a file named fluffy.jar:"
echo " zip c fluffy.jar qgpl/mysavf"
echo " Example 2: to restore a save file from a file named squished.zip:"
echo " zip r squished.zip"
echo " Explicit or relative paths may be used (I hope):"
echo " zip c /qibm/smashed.flat mylibrary/mysavf"
echo " zip r ./mysubdirectory/savf.jar"
echo " Example 3: to display the contents of a zip file named squished.zip:"
echo " zip d squished.zip"
echo
echo " Questions? Comments? Grumbles? Gripes? Send them to me: mikswens@us.ibm.com"
echo " ...they will be ignored in the order recieved :-)"
exit 1;
fi
# Check the validity of the jarfile parameter. If it exists and the fuction is compression,
# then prompt to overwrite the file or not.
# For restore operations the jarfile must be converted to an explicit path.
JARFILE=$2
if [[ -e "$JARFILE" && $FUNCTION == C ]]
then
echo "File $JARFILE already exists, overwrite existing file? (Y,N)"
read OVRWRT
declare -u UOVRWRT=$OVRWRT
if [ "$UOVRWRT" == Y ]
then
echo "...overwriting file."
elif [ "$UOVRWRT" == N ]
then
echo "OK. exiting zip function."
exit 2
else
echo "What was that supposed to mean? The choices are Y or N."
exit 10
fi
fi
if [ ! -e "$JARFILE" ]
then
if [ "$FUNCTION" == R ]
then
echo "File $JARFILE not found. Nothing to restore."
exit 3
elif [ "$FUNCTION" == D ]
then
echo "File $JARFILE not found. Nothing to display."
exit 3
fi
else # put an explicit path onto the jarfile
if [[ ${JARFILE:0:2} == ./ ]]
then
JARFILE=$PWD/${JARFILE#./}
elif [[ ${JARFILE:0:1} != / ]]
then
JARFILE=$PWD/$JARFILE
fi
fi
# Compress the file
if [[ $FUNCTION == C ]]
then
LIBFILENAME=$3
declare -u IFSPATH="/QSYS.LIB/${LIBFILENAME%/*}.LIB/${LIBFILENAME#*/}.FILE"
if [[ ! -e "$IFSPATH" ]]
then
echo "File $IFSPATH does not exist. Nothing to compress."
exit 3
else
jar cvfM $JARFILE $IFSPATH
fi
fi
# Restore the file
if [[ $FUNCTION == R ]]
then
cd / ; jar xvf $JARFILE
fi
# Display jar file contents
if [[ $FUNCTION == D ]]
then
echo jar file $JARFILE
echo "_________________________________________________________"
jar tf $JARFILE
echo "_________________________________________________________"
fi
[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CHQAA2","label":"Qshell"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]
Historical Number
368629099
Was this topic helpful?
Document Information
Modified date:
15 November 2024
UID
nas8N1015691