bvstone

Performing IBM i (AS400, iSeries, System i) Backups using Google Drive

Posted:

Performing IBM i (AS400, iSeries, System i) Backups using Google Drive

Recently we released the Google Drive Addon (G4GGDRV) for GreenTools for Google Apps (G4G).  

We did this because we wanted an easier way to perform backups on our IBM i using "the cloud".  Because we use Google for our business we have plenty of space for backing up our data.

Really there's nothing different to this than saving to tape, except we add a few extra steps.

Here's the CL Source code we use for this:

             PGM
             DCLF       FILE(BACKUPPF)
             DCL        VAR(&FILEN) TYPE(*CHAR) LEN(128)
             DCL        VAR(&ZIPFILE) TYPE(*CHAR) LEN(128)
             DCL        VAR(&IFSDIR) TYPE(*CHAR) LEN(128)
             DCL        VAR(&SAVEF) TYPE(*CHAR) LEN(128)
             DCL        VAR(&IFSSAVEF) TYPE(*CHAR) LEN(128)
             DCL        VAR(&FQZIP) TYPE(*CHAR) LEN(128)
             DCL        VAR(&CMD) TYPE(*CHAR) LEN(128)

READ:
             RCVF
             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(END))

             CHGVAR     VAR(&FILEN) VALUE(&NAME *TCAT '.savf')
             CHGVAR     VAR(&ZIPFILE) VALUE(&NAME *TCAT '.zip')
             CHGVAR     VAR(&IFSDIR) VALUE('/backups')
             CHGVAR     VAR(&SAVEF) VALUE('/qsys.lib/qgpl.lib/' +
                          *TCAT &NAME *TCAT '.file')
             CHGVAR     VAR(&IFSSAVEF) VALUE(&IFSDIR *TCAT '/' *TCAT +
                          &FILEN)
             CHGVAR     VAR(&FQZIP) VALUE(&IFSDIR *TCAT '/' *TCAT +
                          &ZIPFILE)

             CRTSAVF    FILE(BVSTONEO/&NAME)
             MONMSG     MSGID(CPF0000)

             CLRSAVF    FILE(BVSTONEO/&NAME)

             IF         COND(&TYPE *EQ 'lib') THEN(DO)
             SAVLIB     LIB(&NAME) DEV(*SAVF) SAVF(BVSTONEO/&NAME) +
                          CLEAR(*ALL) SAVACT(*LIB)
             MONMSG     MSGID(CPF0000)
             ENDDO

             IF         COND(&TYPE *EQ 'ifs') THEN(DO)
             SAV        DEV(&SAVEF) OBJ((&PATH)) SUBTREE(*ALL) +
                          SAVACT(*YES)
             MONMSG     MSGID(CPF0000)
             ENDDO

             CPYTOSTMF  FROMMBR(&SAVEF) TOSTMF(&IFSSAVEF) +
                          STMFOPT(*REPLACE) STMFCODPAG(819)
             MONMSG     MSGID(CPF0000)

             CHGVAR     VAR(&CMD) VALUE('cd /backups; jar -cf' *BCAT +
                          &ZIPFILE *BCAT &SAVEF)
             QSH        CMD(&CMD)
             MONMSG     MSGID(CPF0000)

             G4GUPLOAD  ID(xxx@xxx.xxx) STMF(&FQZIP) +
                          TOFLR('/MyPath/AS400 Stuff/Backups')
             MONMSG     MSGID(CPF0000)

             GOTO       CMDLBL(READ)

END:

             ENDPGM

First, we have a file named BACKUPPF with the following layout:

File Name . . . . BACKUPPF                            
  Library . . . .   FILELIB
Format Descr  . .                                     
Format Name . . . RBACKUP    
File Type . . . . PF            Unique Keys - N 
                                                      
Field Name FMT Start Lngth Dec Key Field Description  
TYPE        A      1    10         Save Type          
NAME        A     11    10         Library Name       
PATH        A     21   128         IFS Path           

TYPE is the type of file(s) to backup.  This is either a library or ifs object.

NAME is the name of the library and/or save file we will use (minus any extension).

PATH is the path we want to save if this is an IFS object.

The first thing our CL does is read in the first record.  If there is no error, it builds a few variables that will be used throughout the program.  

FILEN is used to hold the filename and .savf extension of our save file.  ZIPFILE is the name of the file after it is zipped (using JAR and QSHELL).  IFSDIR defines the directory in the IFS that we will be placing the files.  SAVEF is the fully qualified path to the save file, using the IFS naming convention.  FQZIP is the Fully Qualified path and name of the zip file that we will end up uploading to our Google Drive.

Next, we check the object type to save.  Depending on if it is a library or IFS location, we run the appropriate SAVLIB or SAV command.

Once we have a save file, we copy that to the IFS using the CPYTOSMTF command.

Next we use QSHELL and the JAR command to compress the save file.  JAR and ZIP use pretty much the same algorithm so there's really no need for an extra ZIP package.

Finally, we call the G4GUPLOAD command, which is part of the Google Drive Addon for G4G, and upload the ZIP file to the appropriate location on our Google Drive.

Fairly simple and very functional.  You could even combine this with the the Google Calendar Addon to fire off this backup job daily, weekly, or whenever you want.  The possibilities are really endless.


Last edited 02/08/2015 at 14:33:31




Reply




© Copyright 1983-2024 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, TinyMCE and running on the IBM i (AKA AS/400, iSeries, System i).