2022

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Setting up

...

Introduction

This document describes the setting up of the DBSync project on a server/local environment and executing it.

It consists of 3 aspects:

...

GCloud Console Project

...

...

Setting up the server/local environment.

...

Building and Executing the project.

...

Demo Login Creds

Reference Youtube: https://youtu.be/aFshfKg2jCI

Prerequisites

Before we proceed, there are some prerequisites needed in the environment. Following are those:

  1. JDK 11 (I believe both OpenJDK and Oracle JDK should work)

  2. Maven 3.X

  3. Spring Tool Suite (Not Mandatory, as you can run the app from command line as well)

  4. G Suite Login (Super Admin Login)

  5. MySql

  6. Folders created on the server/local environment where the backup should happen.

Setting up GCloud Console Project

The very first step should be to create and setup set up a GCloud Console Project. Following are the steps to do so:

...

  • navbar project selector, you will see an option to create a “New Project” in the panel that shows up once you click the project selector.
  • Enter the project name, organization, and location and create the project.

Then the next step is to create a service account, use the following steps to do so:

  • Make sure that you have selected the newly created project from the project selector on the top

...

  • navbar.
  • Once selected, from the left menu, under “APIs & Services” select “Credentials”.
  • Click “Manage Service Account” and under the Service Accounts

...

  • page, click the “Create Service Account” button on the top.
  • Give a proper name to the service account (Our code should not affect the name that is used).
  • It will pre-fill email, update in case you want to change as this would not affect our code.
  • Enter a proper description, again this should not affect the code.
  • Click “Create”
  • Once created, it will ask to select a Role, select Project > Owner as the role, and click Continue.

...

  • The next step is to grant service account access, there are 2 text boxes, in both the text boxes, enter the super admin account email id and click “Done”.
  • Once created, it will take you to the Service Account Manage page where the newly created Service Account will be listed.
  • Click on the Service Account and it will take you to the Service Account Details page. Click Edit to start editing the account.

...

Click on the “Show Domain Wide Delegation” link and Enable Domain wide delegation by checking the checkbox. Note to wait for a few mins in case the checkbox is disabled, as we noticed that it takes a few mins to have the checkbox enabled.

...

Enter proper Product Name here.

...

Click Save.

  • Once saved, under the Keys section, Create a new key, use JSON format. Make sure you download the key as it would not let you download the key later.

...

  •  
  • On the Service Account Details page, make sure you copy the Unique Id shown on that page as we will need it later (It will look something

...

  • similar to '117173051217199643714')

Now it’s time to setup set up the libraries, use the following steps to set it up:

  • Make sure that you have selected the newly created project from the project selector on the top

...

  • navbar.
  • Once selected, from the left menu, under “APIs & Services” select “Library”.
  • Enable the following APIs for our project:
    1. Admin SDK

    2. Gmail API

    3. Google Drive API

    4. Google Calendar API

    5. People API

  • Once enabled you will see the enabled list under APIs & Services > Dashboard.
  • Once APIs are enabled for the project, we have to now setup Scopes, use the following steps to do the same

...

  • Go to: https://admin.google.com/
  • Login using the Super Admin Credentials.
  • Under “Security” go to “API Controls” and click “Manage Domain Wide Delegation”
  • Click on “Add New” and enter the unique ID copied in the above step inside the Client ID textbox.
  • Add the following list of scopes

...

  • (comma separated)

...

...

  1. Once done, click “Authorize”.

Now, it’s time to create a OAuth Client, use the following steps to do so:

  1. Make sure that you have selected the newly created project from the project selector on the top nav bar.

  2. Once selected, from the left menu, under “APIs & Services” select “Credentials”.

  3. Click “Create Credentials” from the top nav bar and select OAuth Client ID.

  4. Select a “Desktop Application” for now since we do not have this application hosted anywhere.

  5. Give an appropriate name and click “Create”.

  6. Download the client secret on your environment and name it client_credentials.json

Setting up the server/local environment

Once the GCloud project is set up, we should now set up the local environment. Following steps to do so:

...

...

The code is pushed on the master branch.

...

Copy the 2 files downloaded GCloud Project (g_suite_credentials.json and client_credentials.json) and save it under src/main/resources folder.

...

In MySQL create a new database and enter the credentials in application.properties under src/main/resources

...

Update the following properties based on the DB Name, and your MySQL setup:

  1. spring.datasource.url

  2. spring.datasource.username

  3. Spring.datasource.password

...

Create a folder where you want all the backup files to be stored and update the following from application.properties:

  1. EML_FILE_PATH

  2. ICS_FILE_PATH

  3. VCARD_FILE_PATH

  4. DRIVE_FILE_PATH

...

If you want to backup all users then in application.properties set the following property to ALL:

  1. include.users.backup

...

Else set it to comma separated emails for any specific users you want to take a backup of.

Once the above is done, you are all set to execute the project.

Building and Executing the project

Once the above is set up following process to build and execute the project:

...

Build the project using maven clean install -DskipTests

...

Once build is complete, there will be a target folder generated and inside it will be a JAR file with the name: DbSync-0.0.1-SNAPSHOT.jar

...

Use the following command to execute the project:

  1. java -jar DbSync-0.0.1-SNAPSHOT.jar

  2. Make sure you copy the jar out of the target folder to some other location and then run the app.

...

The execute the following APIs for each of the backup to execute:

...

  • Once done, click “Authorize”.
  • Now use this special generated key Json in the DBSync GSuite Setup page.