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:

Create QRCODE in DDS Create QRCODE in DDS
Posted by September 21, 2018
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).