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




Reply




© Copyright 1983-2024 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).