FreeSBC:Uploading backups to Google Cloud Bucket

From TBwiki
(Difference between revisions)
Jump to: navigation, search
Line 78: Line 78:
 
Your active configuration is: [default]
 
Your active configuration is: [default]
 
</pre>
 
</pre>
 +
 +
==Transferring files to Bucket==
 +
 +
This section shows you how to upload objects to your Cloud Storage bucket. An uploaded object consists of the data you want to store along with any associated metadata.
 +
 +
Use the '''gsutil cp''' command:
 +
 +
<pre>
 +
gsutil cp OBJECT_LOCATION gs://DESTINATION_BUCKET_NAME/
 +
</pre>
 +
 +
Where:
 +
 +
* '''OBJECT_LOCATION''' is the local path to your backup file. For example, /lib/tb/toolpack/pkg/database_backups for the ProSBC backup location.
 +
 +
* '''DESTINATION_BUCKET_NAME''' is the name of the bucket to which you are uploading your object. For example, my-bucket.
 +
 +
If successful, the response looks like the following example:
 +
 +
<pre>
 +
Operation completed over 1 objects/58.8 KiB.
 +
</pre>
 +
 +
You can check the following link for code samples written in the most popular languages;
 +
 +
* [https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-code-sample]

Revision as of 06:26, 30 December 2020

In this tutorial, we are going to help you use Google gsutil to access Google Bucket. We will do this so you can easily build your own scripts for backing up your files to the cloud and easily retrieve them as needed.

Install and Configure Google Cloud SDK

Cloud SDK is available in package format for installation on Red Hat Enterprise Linux 7, Red Hat Enterprise Linux 8, Fedora 32, and CentOS 7 systems. This package contains the gcloud, gcloud alpha, gcloud beta, gsutil, and bq commands.

1. Update repository with Cloud SDK repo information:

sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM

2. Install the Cloud SDK:

 yum install google-cloud-sdk 

Initializing the Cloud SDK

Use the gcloud init command to perform several common Cloud SDK setup tasks. These include authorizing the Cloud SDK tools to access Google Cloud using your user account credentials and setting up the default configuration.

To initialize the Cloud SDK:

1. Run the following at a command prompt:

 gcloud init 

2. Accept the option to log in using your Google user account:

 To continue, you must log in. Would you like to log in (Y/n)? Y 

3. In your browser, log in to your Google user account when prompted and click Allow to grant permission to access Google Cloud resources.

4. At the command prompt, select a Google Cloud project from the list of those where you have Owner, Editor or Viewer permissions:

Pick cloud project to use:
 [1] [my-project-1]
 [2] [my-project-2]
 ...
 Please enter your numeric choice:

If you only have one project, gcloud init selects it for you.

If you have access to more than 200 projects, you will be prompted to enter a project id, create a new project, or list projects.

This account has a lot of projects! Listing them all can take a while.
 [1] Enter a project ID
 [2] Create a new project
 [3] List projects
Please enter your numeric choice:

5. If you have the Google Compute Engine API enabled, gcloud init allows you to choose a default Compute Engine zone:

Which compute zone would you like to use as project default?
 [1] [asia-east1-a]
 [2] [asia-east1-b]
 ...
 [14] Do not use default zone
 Please enter your numeric choice:

gcloud init confirms that you have complete the setup steps successfully:

gcloud has now been configured!
You can use [gcloud config] to change more gcloud settings.

Your active configuration is: [default]

Transferring files to Bucket

This section shows you how to upload objects to your Cloud Storage bucket. An uploaded object consists of the data you want to store along with any associated metadata.

Use the gsutil cp command:

gsutil cp OBJECT_LOCATION gs://DESTINATION_BUCKET_NAME/

Where:

  • OBJECT_LOCATION is the local path to your backup file. For example, /lib/tb/toolpack/pkg/database_backups for the ProSBC backup location.
  • DESTINATION_BUCKET_NAME is the name of the bucket to which you are uploading your object. For example, my-bucket.

If successful, the response looks like the following example:

Operation completed over 1 objects/58.8 KiB.

You can check the following link for code samples written in the most popular languages;

Personal tools