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:

Using GETURI to Make OAuth 2.0 Requests - Custom Headers for Access Tokens Using GETURI to Make OAuth 2.0 Requests - Custom Headers for Access Tokens
Posted by 2 days ago
BVSTools >> BVSTools Software Discussion >> Get URI (GETURI) Specific Discussion
GreenTools for Microsoft Apps (G4MS) v5.00 Released with Updated OneDrive Support and 3rd Party Functionality GreenTools for Microsoft Apps (G4MS) v5.00 Released with Updated OneDrive Support and 3rd Party Functionality
Posted by October 20, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
BVSTools is Now Running V7R4M0 BVSTools is Now Running V7R4M0
Posted by September 28, 2019
BVSTools >> BVSTools Announcements
GreenTools for G Suite (G4G) Now Includes Send Mail Functionality (G4GSMAIL Addon) GreenTools for G Suite (G4G) Now Includes Send Mail Functionality (G4GSMAIL Addon)
Posted by August 27, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools For G Suite (G4G) v12.00 Released With Base OAuth 2.0 Functionality GreenTools For G Suite (G4G) v12.00 Released With Base OAuth 2.0 Functionality
Posted by July 28, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
BVSTools Small Price Increase in 2020 BVSTools Small Price Increase in 2020
Posted by July 26, 2019
BVSTools >> BVSTools Announcements
GreenTools for Vertex Cloud (VTXCLOUD) Now Available GreenTools for Vertex Cloud (VTXCLOUD) Now Available
Posted by July 22, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Vertex Cloud (VTXCLOUD) Specific Announcements
GreenTools for Google Apps (G4G) - Drive Addon Successfully Verified by Google GreenTools for Google Apps (G4G) - Drive Addon Successfully Verified by Google
Posted by July 22, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Why I Cancelled my DynDNS Service and How I Replaced It with an IBM i Application Why I Cancelled my DynDNS Service and How I Replaced It with an IBM i Application
Posted by July 17, 2019
IBM Power Systems >> (QGPL) IBM i
Green Tools for G Suite (G4G) Product Updates (Licensing, Functionality, Base Product) Green Tools for G Suite (G4G) Product Updates (Licensing, Functionality, Base Product)
Posted by July 13, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Reading JSON Data from Standard Input With YAJL and RPG Reading JSON Data from Standard Input With YAJL and RPG
Posted by July 12, 2019
Programming >> Proof of Concept (POC)
MAILTOOL Updated to Allow Use of IBM Global Security Kit (GSKIT) for SSL/TLS Communications MAILTOOL Updated to Allow Use of IBM Global Security Kit (GSKIT) for SSL/TLS Communications
Posted by June 19, 2019
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
GETURI v10.00 Released Supporting IBM Global Security Kit (GSKIT) and Server Name Indication (SNI) GETURI v10.00 Released Supporting IBM Global Security Kit (GSKIT) and Server Name Indication (SNI)
Posted by June 11, 2019
BVSTools >> BVSTools Announcements >> Get URI (GETURI) Specific Announcements
BVSTools Now Offers Vertex Cloud Interface BVSTools Now Offers Vertex Cloud Interface
Posted by April 15, 2019
BVSTools >> BVSTools Announcements
Token Has an Invalid Signature Error for Office 365 Email Token Has an Invalid Signature Error for Office 365 Email
Posted by March 22, 2019
BVSTools >> BVSTools Software Discussion >> GreenTools for Microsoft Apps (G4MS) Specific Discussion

Reply




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