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



Latest Posts:

Create QRCODE in DDS Create QRCODE in DDS
Posted by 3 days ago
Programming >> RPG Programming
Base64 Encoding a File with RPG Base64 Encoding a File with RPG
Posted by September 6, 2018
Programming >> RPG Programming
Building JSON with RPG and YAJL and Writing to Standard Output Building JSON with RPG and YAJL and Writing to Standard Output
Posted by August 31, 2018
Programming >> Proof of Concept (POC)
How to Delete Files or Empty Trash From Your Google Drive with your IBM i and RPG/ILE How to Delete Files or Empty Trash From Your Google Drive with your IBM i and RPG/ILE
Posted by July 24, 2018
BVSTools >> BVSTools Software Discussion >> GreenTools for G Suite (Google Apps) (G4G) Specific Discussion
GreenTools for G Suite (G4G) Updated to Include Delete and Empty Trash Function GreenTools for G Suite (G4G) Updated to Include Delete and Empty Trash Function
Posted by July 24, 2018
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
What to Do If Your License Keys Don't Work What to Do If Your License Keys Don't Work
Posted by July 18, 2018
BVSTools >> BVSTools Software Discussion
MAILTOOL Updated to Allow Failed Message on Invalid Recipient MAILTOOL Updated to Allow Failed Message on Invalid Recipient
Posted by May 20, 2018
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
Non HTTPS Callbacks Removed from GreenTools for G Suite (G4G) Non HTTPS Callbacks Removed from GreenTools for G Suite (G4G)
Posted by April 15, 2018
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
IBM i Related Survey Available IBM i Related Survey Available
Posted by April 7, 2018
IBM Power Systems >> (QGPL) IBM i
BVSTools Releases Braintree Webhook Open Source Application - Node.js BVSTools Releases Braintree Webhook Open Source Application - Node.js
Posted by April 5, 2018
Programming >> Open Source
BVSTools Now Offering Web Services (BETA) BVSTools Now Offering Web Services (BETA)
Posted by April 3, 2018
BVSTools >> BVSTools Announcements
Creating a Reverse SSL Proxy Using RPG on the IBM i - Part 2 Creating a Reverse SSL Proxy Using RPG on the IBM i - Part 2
Posted by March 29, 2018
Programming >> Web Programming
Still on V7R1 or Earlier?  Here's Why You Should Upgrade NOW! Still on V7R1 or Earlier? Here's Why You Should Upgrade NOW!
Posted by February 21, 2018
IBM Power Systems >> (QGPL) IBM i
Converting a MMDDYY date format to YYMMDD for Sorting Using SQL Converting a MMDDYY date format to YYMMDD for Sorting Using SQL
Posted by February 16, 2018
Programming >> RPG Programming
Moving All Files from a Google Drive Folder to the Trash Using GreenTools for Google Apps (G4G) Moving All Files from a Google Drive Folder to the Trash Using GreenTools for Google Apps (G4G)
Posted by February 3, 2018
BVSTools >> BVSTools Software Discussion >> GreenTools for G Suite (Google Apps) (G4G) Specific Discussion

Reply




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