Created
May 27, 2020 11:20
-
-
Save NielsLiisberg/1dbdd0817510aec56ee7410effce2a51 to your computer and use it in GitHub Desktop.
SQL save and restore from/to IFS or restore directly from the web by HTTP or HTTPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Saves and restores Library into streamfile. local on the IFS or direct with HTTP from an URL | |
-- Note1: This uses my ftp_put_ifs and webget, also found on my Gist | |
-- Note2: I am using library QUSRSYS. I suggest you put it into your own tool library | |
-- It is a cool example how far you can go with SQL: Have fun - | |
-- (C) Niels Liisberg 2020 | |
---------------------------------------------------------------------------------------------- | |
create or replace procedure qusrsys.savlib_to_ifs ( | |
library char(10), | |
stmf varchar(256) | |
) | |
set option output=*print, commit=*none, dbgview=*list | |
begin | |
declare continue handler for sqlstate value '38501' begin | |
end; | |
call qcmdexc('crtsavf qtemp/q'); | |
call qcmdexc('clrsavf qtemp/q'); | |
call qcmdexc('savlib LIB(' || library || ') DEV(*SAVF) SAVF(QTEMP/Q)'); | |
call qcmdexc('cpytostmf FROMMBR(''/QSYS.LIB/QTEMP.LIB/Q.FILE'') TOSTMF(''' || stmf || ''') STMFOPT(*REPLACE) CVTDTA(*NONE) STMFCCSID(1252)'); | |
end; | |
create or replace procedure qusrsys.rstlib_from_ifs ( | |
library char(10), | |
stmf varchar(256) | |
) | |
set option output=*print, commit=*none, dbgview=*list | |
begin | |
call qcmdexc('CPYFRMSTMF FROMSTMF(''' || stmf || ''') TOMBR(''/QSYS.LIB/QTEMP.LIB/Q.FILE'') MBROPT(*REPLACE) CVTDTA(*NONE)'); | |
call qcmdexc('RSTLIB SAVLIB(' || library || ') DEV(*SAVF) SAVF(QTEMP/Q)'); | |
end; | |
create or replace procedure qusrsys.rstlib_from_web ( | |
library char(10), | |
url varchar(1024) | |
) | |
set option output=*print, commit=*none, dbgview=*list | |
begin | |
declare stmf varchar(256); | |
set stmf = '/tmp/' || translate(char(now()) , '--', ' .' ) || '.savf'; | |
call qusrsys.webget (url , stmf); | |
call qcmdexc('CPYFRMSTMF FROMSTMF(''' || stmf || ''') TOMBR(''/QSYS.LIB/QTEMP.LIB/Q.FILE'') MBROPT(*REPLACE) CVTDTA(*NONE)'); | |
call qcmdexc('RSTLIB SAVLIB(' || library || ') DEV(*SAVF) SAVF(QTEMP/Q)'); | |
call qcmdexc('RMVLNK ''' || stmf || ''''); | |
end; | |
-- test use case: | |
call qusrsys.savlib_to_ifs ( | |
library => 'ILEASTIC', | |
stmf => '/tmp/ILEastic.savf' | |
); | |
call qusrsys.rstlib_from_ifs ( | |
library => 'ILEASTIC', | |
stmf => '/tmp/ILEastic.savf' | |
); | |
-- The web puts the save file with FTP you can finde elsewhere on my gist: | |
call qusrsys.ftp_put_ifs ( | |
host => 'webfiles.mysite.com', | |
userid => 'myname', | |
password => 'mypassword', | |
from_file => '/tmp/ILEastic.savf', --<-- Local stream files on the IFS | |
to_dir => '/webfiles' --<-- remote folder on the FTP server | |
); | |
call qusrsys.rstlib_from_web ( | |
library => 'ILEASTIC', | |
url => 'http://webfiles.system-method.com/ILEastic.savf' | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment