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:

QuickBooks Online - Subtotals and Discounts Frustration QuickBooks Online - Subtotals and Discounts Frustration
Posted by March 16, 2023
QuickBooks >> QuickBooks Online
Making the Switch From QuickBooks Desktop to QuickBooks Online - No Picnic Making the Switch From QuickBooks Desktop to QuickBooks Online - No Picnic
Posted by March 16, 2023
QuickBooks >> QuickBooks Online
BVSTools Software Verified on V7R5 and Power10 BVSTools Software Verified on V7R5 and Power10
Posted by December 9, 2022
BVSTools >> BVSTools Announcements
Microsoft Office 365 Servers and Random Errors Issue Microsoft Office 365 Servers and Random Errors Issue
Posted by November 14, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Sending/Resending Emails Using a MIME File with MAILTOOL Sending/Resending Emails Using a MIME File with MAILTOOL
Posted by November 8, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Sending an HTML Email on Your IBM i Using MAILTOOL Sending an HTML Email on Your IBM i Using MAILTOOL
Posted by November 1, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Transferring License Keys from One System to Another Transferring License Keys from One System to Another
Posted by October 31, 2022
BVSTools >> BVSTools Software Discussion
Calculating the Size of a File Before Base64 Encoding Calculating the Size of a File Before Base64 Encoding
Posted by August 13, 2022
Programming >> RPG Programming
GreenTools for Microsoft Apps (G4MS) v9.12 Now Includes Function to Send Emails using MIME File GreenTools for Microsoft Apps (G4MS) v9.12 Now Includes Function to Send Emails using MIME File
Posted by August 11, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
GreenTools for Google Apps (G4G) v15.20 Now Supports Shortcuts GreenTools for Google Apps (G4G) v15.20 Now Supports Shortcuts
Posted by August 6, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools for Microsoft Apps (G4MS) Groups Admin Authority Instructions GreenTools for Microsoft Apps (G4MS) Groups Admin Authority Instructions
Posted by July 26, 2022
BVSTools >> BVSTools Software Discussion >> GreenTools for Microsoft Apps (G4MS) Specific Discussion
GreenTools for Microsoft Apps (G4MS) v9.10 Now Includes OneDrive Functions that Work With Groups/Shared Drives GreenTools for Microsoft Apps (G4MS) v9.10 Now Includes OneDrive Functions that Work With Groups/Shared Drives
Posted by July 19, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
GreenTools for Google Apps (G4G) v15.10 Now Includes Drive Functions that Work With Shared Drives GreenTools for Google Apps (G4G) v15.10 Now Includes Drive Functions that Work With Shared Drives
Posted by July 15, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page
Posted by July 4, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
What Objects Should I Omit from Replication to Ensure My License Keys Work on my HA/DR System? What Objects Should I Omit from Replication to Ensure My License Keys Work on my HA/DR System?
Posted by June 27, 2022
BVSTools >> BVSTools Software Discussion

Reply




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