2022

Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

  • Enter login credentials

  • You will be redirected to the apps page.

  • Select the profile from the landing page. Current example has admin user privileges. 

  • Click the GSuite icon from the top navigation toolbar

  • You will be redirected to the settings page

GSuite Backup setting important fields :

    1. Domain - Organization URL to be added here

    2. Email - admin user email address

    3. Key Value - this is to be gathered using the steps listed below:

Setting up GCloud Console Project

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

  1. Go to: https://console.cloud.google.com

  2. Login using the super admin credentials.

  3. Once logged in, click the top nav bar project selector, you will see an option to create a “New Project” in the panel that shows up once you click the project selector.

  4. 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:

  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 “Manage Service Account” and under the Service Accounts Page, click the “Create Service Account” button on the top.

  4. Give a proper name to the service account (Our code should not affect the name that is used).

  5. It will pre-fill email, update in case you want to change as this would not affect our code.

  6. Enter proper description, again this should not affect the code.

  7. Click “Create”

  8. Once created, it will ask to select a Role, select Project > Owner as the role and click Continue.

  9. 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”.

  10. Once created, it will take you to the Service Account Manage page where the newly created Service Account will be listed.

  11. Click on the Service Account and it will take you to the Service Account Details page. Click Edit to start editing the account.

  12. 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.

  13. Enter proper Product Name here.

  14. Click Save.

  15. 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. Download the file as g_suite_credentials.json

  16. One 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 like: 117173051217199643714)

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

  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 “Library”.

  3. Enable the following APIs for our project:

    1. Admin SDK

    2. Gmail API

    3. Google Drive API

    4. Google Calendar API

    5. People API

  4. 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:

  1. Go to: https://admin.google.com/

  2. Login using the Super Admin Credentials.

  3. Under “Security” go to “API Controls” and click “Manage Domain Wide Delegation”

  4. Click on “Add New” and enter the unique ID copied in above step inside the Client ID textbox.

  5. Add the following list of scopes:

    1. https://mail.google.com/

    2. https://www.googleapis.com/auth/gmail.readonly

    3. https://www.googleapis.com/auth/gmail.settings.sharing

    4. https://www.googleapis.com/auth/gmail.settings.basic

    5. https://www.googleapis.com/auth/gmail.addons.current.action.compose

    6. https://www.googleapis.com/auth/gmail.modify

    7. https://www.googleapis.com/auth/gmail.labels

    8. https://www.googleapis.com/auth/gmail.compose

    9. https://www.googleapis.com/auth/gmail.send

    10. https://www.googleapis.com/auth/gmail.insert

    11. https://www.googleapis.com/auth/contacts.other.readonly

    12. https://www.googleapis.com/auth/contacts.readonly

    13. https://www.googleapis.com/auth/contacts

    14. https://www.googleapis.com/auth/drive.readonly

    15. https://www.googleapis.com/auth/drive.file

    16. https://www.googleapis.com/auth/drive

    17. https://www.googleapis.com/auth/calendar

    18. https://www.googleapis.com/auth/calendar.events

    19. https://www.googleapis.com/auth/cloud-platform

    20. https://www.googleapis.com/auth/admin.directory.user.security

    21. https://www.googleapis.com/auth/admin.directory.user.readonly

    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:

  1. The code is pushed on the bitbucket repository: https://bitbucket.org/outsourced-projects/google-cloud-backup/src/master/

  2. The code is pushed on the master branch.

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

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

  5. 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

  6. 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

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

    1. include.users.backup

  8. 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:

  1. Build the project using maven clean install -DskipTests

  2. 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

  3. 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.

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

    1. Gmail backup - GET : http://localhost:8080/dbsync/mails

    2. Drive backup - GET : http://localhost:8080/dbsync/drive

    3. Calendar events backup - GET : http://localhost:8080/dbsync/events

    4. Contacts backup - GET : http://localhost:8080/dbsync/contacts

  • No labels