bvstone

Backing up your IBM i (iSeries, AS/400, System i) Files to the Cloud (Both Google Drive and Microsoft OneDrive)

Posted:

Backing up your IBM i (iSeries, AS/400, System i) Files to the Cloud (Both Google Drive and Microsoft OneDrive)

We have previously discussed how to back up your IBM i files to Google Drive using our GreenTools for Google Drive (G4G).

We also recently released a similar utility that allows you to upload files to your Microsoft OneDrive as well.  This utility is named GreenTools for Microsoft Apps (G4MS).

Both of these utilities have commands as well as ILE interfaces that can be used to take advantage of their functionality.  

Because our previous example used a CL program and the commands, we thought we would put together an RPG version that uses the ILE functions and also adds redundancy to backup to BOTH our Google Drive and OneDrive accounts.

The File

We start off the same -- with a file that we can add and remove entries to so that if we decide to backup more libraries or IFS folders we can simple add entries.  The file layout is as follows:

File Name . . . . BACKUPPF                                   
  Library . . . .   BVSTONES                                 
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                  

Now, the "TYPE" field before was used to tell us if it was a library or an IFS file.  In this new version we don't need this anymore as we changed all the SAVLIB commands to use SAV, the same command we use for saving IFS objects.

Some sample data looks like this:

TYPE        NAME        PATH
lib         bvscomp     /qsys.lib/bvscomp.lib
ifs         wwwifs      /www
lib         bvstools    /qsys.lib/bvstools.lib
ifs         bvstoolsif  /bvstools
lib         bvstoolsv4  /qsys.lib/bvstoolsv4.lib

Here we see a mix of IFS objects and Libraries we wish to save.  As mentioned the "TYPE" column really isn't used in this new application.  The "NAME" column is used to name the save file, and the "PATH" column is used to determine which libraries or IFS paths to save.

Our RPG program looks like the following:

     FBACKUPPF  IF   E             DISK
      *******************************************************
      /copy qcopysrc,p.libl
      /copy qcopysrc,p.g4gdrv
      /copy qcopysrc,p.g4msdrv
      *******************************************************
     D #QCmdExc        PR                  ExtPgm('QCMDEXC')
     D  Cmd                       32000    Const
     D  CmdLen                       15  5 Const
      ******************************************************
     D fileName        S            256    Varying
     D saveFile        S            256    Varying
     D command         S            256
      *******************************************************
      /free

       #pushLib('GETURI');
       #pushLib('G4GBVS');
       #pushLib('G4MSBVS');

       read backuppf;

       dow (not %eof(backuppf));
         fileName = %trimr(NAME);
         saveFile = '/qsys.lib/bvstoneo.lib/' + fileName + '.file';

         // Create the Save File
         Command = 'CRTSAVF FILE(BVSTONEO/' + fileName + ')';
         callp(e) #QCmdExc(Command:%len(Command));

         // Clear the Save File
         Command = 'CLRSAVF FILE(BVSTONEO/' + fileName + ')';
         callp(e) #QCmdExc(Command:%len(Command));

         // Save the object
         Command = 'SAV DEV(''' + saveFile + ''') ' +
                   'OBJ((''' + %trimr(PATH) + ''')) SUBTREE(*ALL) SAVACT(*YES)';
         callp(e) #QCmdExc(Command:%len(Command));

         // Copy the Save File to the IFS
         Command = 'CPYTOSTMF FROMMBR(''' + saveFile + ''') TOSTMF(''' +
                   '/backups/' + fileName + '.savf'') ' +
                   'STMFOPT(*REPLACE) STMFCODPAG(819)';
         callp(e) #QCmdExc(Command:%len(Command));

         // Zip the IFS Save File
         Command = 'QSH CMD(''cd /backups; jar -cf ' + fileName + '.zip ' +
                   fileName + '.savf'')';
         callp(e) #QCmdExc(Command:%len(Command));

         // Upload the Zipped Save File to Google Drive
         #g4gdrv_setValue('id':'me@gmail.com');
         #g4gdrv_setValue('upload_file':'/backups/' + fileName +  '.zip');
         #g4gdrv_setValue('upload_to_folder':'/Backups/AS400');
         #g4gdrv_upload();

         // Upload the Zipped Save File to Micrsoft OneDrive
         #g4msdrv_setValue('id':'me@outlook.com');
         #g4msdrv_setValue('upload_file':'/backups/' + fileName +  '.zip');
         #g4msdrv_setValue('upload_to_folder':'/Backups/AS400');
         #g4msdrv_upload();

         read backuppf;
       enddo;

       #popLib('GETURI');
       #popLib('G4GBVS');
       #popLib('G4MSBVS');

       *INLR = *ON;
      /end-free

When we examine the source what we find is that the uploading is the easy part.  It's the saving and zipping of the save files that is "messy".  

For each record in the BACKUPPF file we perform the following:

  1. Create a Save File
  2. Clear that Save File (in case it already existed)
  3. Save the Library or IFS objects to that Save File
  4. Copy the Save File to the IFS (this is so it can be compressed to a ZIP file)
  5. Zip the IFS Save File using the JAR command
  6. Upload the Zipped file to both our Google Drive and Microsoft OneDrive backup folders

So, as you can see, with the cloud the possibilities for backups open up tremendously.  And, if you have a OneDrive Business account, they have announced there is no limit on the space you can use (although, I believe they have an issue with 20,000 files being the max which they are working on fixing).


Last edited 02/11/2015 at 10:46:10



Latest Posts:

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
Removing Unwanted Characters from a String with RPG Removing Unwanted Characters from a String with RPG
Posted by February 2, 2018
Programming >> RPG Programming
GETURI Version 8.10 Released GETURI Version 8.10 Released
Posted by January 23, 2018
BVSTools >> BVSTools Announcements >> Get URI (GETURI) Specific Announcements
BVSTools is Now a Sponsor of ALLAS400S.com BVSTools is Now a Sponsor of ALLAS400S.com
Posted by January 17, 2018
BVSTools >> BVSTools Announcements
Service Pack SP171219 Released for G4PP v3.10 Service Pack SP171219 Released for G4PP v3.10
Posted by December 20, 2017
BVSTools >> BVSTools Announcements >> GreenTools for PayPal (G4PP) Specific Announcements
GETURI Now Requires Minimum OS of V7R1 or Higher GETURI Now Requires Minimum OS of V7R1 or Higher
Posted by December 12, 2017
BVSTools >> BVSTools Software Discussion >> Get URI (GETURI) Specific Discussion
Need Help Updating Your Software Versions?  We Can Help. Need Help Updating Your Software Versions? We Can Help.
Posted by December 8, 2017
BVSTools >> BVSTools Announcements
Parsing the Response from GreenTools for PayPal (G4PP) Refund Transaction Parsing the Response from GreenTools for PayPal (G4PP) Refund Transaction
Posted by November 27, 2017
BVSTools >> BVSTools Software Discussion >> GreenTools for PayPal (G4PP) 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).