In this topic I would explain how to upload files from on premise machine to oracle cloud using CLI. Many customers like to place their on premise backup into cloud object storage for various reasons. In this post I would share the steps of how to upload the files into OCI object storage.
Install the CLI:-
[root@server1]## bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"
% Total % Received % Xferd Average Speed Time
Time Time Current
Dload Upload
Total Spent Left
Speed
100 16053 100
16053 0 0
26111 0 --:--:-- --:--:--
--:--:-- 26144
******************************************************************************
You have started
the OCI CLI Installer in interactive mode. If you do not wish
to run this in
interactive mode, please include the --accept-all-defaults option.
If you have the
script locally and would like to know more about
input options for
this script, then you can run:
./install.sh -h
If you would like
to know more about input options for this script, refer to:
https://github.com/oracle/oci-cli/blob/master/scripts/install/README.rst
******************************************************************************
Downloading Oracle Cloud Infrastructure CLI install script
from https://raw.githubusercontent.com/oracle/oci-cli/v2.14.4/scripts/install/install.py
to /tmp/oci_cli_install_tmp_tA9G.
########################################################################
100.0%
Running install script.
python3 /tmp/oci_cli_install_tmp_tA9G
-- Verifying Python version.
-- Python version 3.6.8 okay.
===> In what
directory would you like to place the install? (leave blank to use
'/root/lib/oracle-cli'):
-- Creating directory '/root/lib/oracle-cli'.
-- We will install at '/root/lib/oracle-cli'.
===> In what
directory would you like to place the 'oci' executable? (leave blank to use
'/root/bin'):
-- Creating directory '/root/bin'.
-- The executable will be in '/root/bin'.
===> In what
directory would you like to place the OCI scripts? (leave blank to use
'/root/bin/oci-cli-scripts'):
-- Creating directory '/root/bin/oci-cli-scripts'.
-- The scripts will be in '/root/bin/oci-cli-scripts'.
===> Currently supported optional packages are: ['db
(will install cx_Oracle)']
What optional CLI
packages would you like to be installed (comma separated names; press enter if
you don't need any optional packages)?:
-- The optional packages installed will be ''.
-- Trying to use python3 venv.
-- Executing: ['/bin/python3', '-m', 'venv',
'/root/lib/oracle-cli']
-- Executing: ['/root/lib/oracle-cli/bin/pip', 'install',
'--upgrade', 'pip']
Collecting pip
Downloading
https://files.pythonhosted.org/packages/cb/28/91f26bd088ce8e22169032100d4260614fc3da435025ff389ef1d396a433/pip-20.2.4-py2.py3-none-any.whl
(1.5MB)
100% |████████████████████████████████|
1.5MB 1.1MB/s
Installing collected packages: pip
Found existing
installation: pip 9.0.3
Uninstalling
pip-9.0.3:
Successfully
uninstalled pip-9.0.3
Successfully installed pip-20.2.4
-- Executing: ['/root/lib/oracle-cli/bin/pip', 'install',
'--cache-dir', '/tmp/tmpz92don2q', 'wheel', '--upgrade']
Collecting wheel
Downloading
wheel-0.35.1-py2.py3-none-any.whl (33 kB)
Installing collected packages: wheel
Successfully installed wheel-0.35.1
-- Executing: ['/root/lib/oracle-cli/bin/pip', 'install',
'--cache-dir', '/tmp/tmpz92don2q', 'oci_cli', '--upgrade']
Collecting oci_cli
Downloading
oci_cli-2.14.5-py2.py3-none-any.whl (12.2 MB)
|████████████████████████████████|
12.2 MB 29.7 MB/s
Collecting configparser==4.0.2
Downloading
configparser-4.0.2-py2.py3-none-any.whl (22 kB)
Collecting jmespath==0.10.0
Downloading
jmespath-0.10.0-py2.py3-none-any.whl (24 kB)
Collecting terminaltables==3.1.0
Downloading
terminaltables-3.1.0.tar.gz (12 kB)
Collecting PyYAML==5.1.2
Downloading
PyYAML-5.1.2.tar.gz (265 kB)
|████████████████████████████████|
265 kB 53.6 MB/s
Collecting retrying==1.3.3
Downloading
retrying-1.3.3.tar.gz (10 kB)
Collecting arrow==0.14.7
Downloading
arrow-0.14.7-py2.py3-none-any.whl (39 kB)
Collecting click==6.7
Downloading
click-6.7-py2.py3-none-any.whl (71 kB)
|████████████████████████████████|
71 kB 14.0 MB/s
Collecting certifi
Downloading
certifi-2020.11.8-py2.py3-none-any.whl (155 kB)
|████████████████████████████████|
155 kB 58.5 MB/s
Collecting cryptography==2.8
Downloading
cryptography-2.8-cp34-abi3-manylinux2010_x86_64.whl (2.3 MB)
|████████████████████████████████|
2.3 MB 55.0 MB/s
Collecting python-dateutil<3.0.0,>=2.5.3
Downloading
python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
|████████████████████████████████|
227 kB 58.8 MB/s
Collecting pyOpenSSL==18.0.0
Downloading
pyOpenSSL-18.0.0-py2.py3-none-any.whl (53 kB)
|████████████████████████████████|
53 kB 3.4 MB/s
Collecting oci==2.23.5
Downloading
oci-2.23.5-py2.py3-none-any.whl (7.0 MB)
|████████████████████████████████|
7.0 MB 56.1 MB/s
Collecting pytz>=2016.10
Downloading
pytz-2020.4-py2.py3-none-any.whl (509 kB)
|████████████████████████████████|
509 kB 54.4 MB/s
Collecting six==1.14.0
Downloading
six-1.14.0-py2.py3-none-any.whl (10 kB)
Collecting cffi!=1.11.3,>=1.8
Downloading
cffi-1.14.3-cp36-cp36m-manylinux1_x86_64.whl (400 kB)
|████████████████████████████████|
400 kB 53.1 MB/s
Collecting pycparser
Downloading
pycparser-2.20-py2.py3-none-any.whl (112 kB)
|████████████████████████████████|
112 kB 57.6 MB/s
Building wheels for collected packages: terminaltables,
PyYAML, retrying
Building wheel for
terminaltables (setup.py) ... done
Created wheel for
terminaltables: filename=terminaltables-3.1.0-py3-none-any.whl size=15354
sha256=0cf6900d9dfed08a4e0293fd8512f72826a84b1c6274ea3731483ed4e6dc629e
Stored in directory:
/tmp/tmpz92don2q/wheels/86/1b/58/c23af2fe683acd8edc15d5a1268f0242be1ff2cf827fe34737
Building wheel for
PyYAML (setup.py) ... done
Created wheel for
PyYAML: filename=PyYAML-5.1.2-cp36-cp36m-linux_x86_64.whl size=44103
sha256=1c65acd68ee2de5ced16ea5f324d712abe64db6182faee6340ad99e09898f98a
Stored in directory:
/tmp/tmpz92don2q/wheels/d8/9b/e7/75af463b873c119dd444151fc54a8e190c87993593e1fa194a
Building wheel for
retrying (setup.py) ... done
Created wheel for
retrying: filename=retrying-1.3.3-py3-none-any.whl size=11429
sha256=ff8a9a128387ab5cd201fe604ed39460f39d91f7e4b4672aa5cd0b6eb5106354
Stored in directory:
/tmp/tmpz92don2q/wheels/ac/cb/8a/b27bf6323e2f4c462dcbf77d70b7c5e7868a7fbe12871770cf
Successfully built terminaltables PyYAML retrying
Installing collected packages: configparser, jmespath,
terminaltables, PyYAML, six, retrying, python-dateutil, arrow, click, certifi,
pycparser, cffi, cryptography, pyOpenSSL, pytz, oci, oci-cli
Successfully installed PyYAML-5.1.2 arrow-0.14.7
certifi-2020.11.8 cffi-1.14.3 click-6.7 configparser-4.0.2 cryptography-2.8
jmespath-0.10.0 oci-2.23.5 oci-cli-2.14.5 pyOpenSSL-18.0.0 pycparser-2.20
python-dateutil-2.8.1 pytz-2020.4 retrying-1.3.3 six-1.14.0
terminaltables-3.1.0
===> Modify profile to update your $PATH and enable
shell/tab completion now? (Y/n): Y
===> Enter a path
to an rc file to update (file will be created if it does not exist) (leave
blank to use '/root/.bashrc'):
-- Backed up '/root/.bashrc' to '/root/.bashrc.backup'
-- Tab completion set up complete.
-- If tab completion is not activated, verify that
'/root/.bashrc' is sourced by your shell.
--
-- ** Run `exec -l $SHELL` to restart your shell. **
--
-- Installation successful.
-- Run the CLI with /root/bin/oci --help
[root@server1]# exec -l $SHELL
Setup OCI configuration:-
Before setting up OCI configuration , we would require
following information such as OCI user OCID, tenancy OCID, Compartment OCID , region etc.
To find out OCI user OCID
To find out tenancy OCID
To find out compartment id
Select the compartment where the oci instance belongs to.
[root@ccuine23 ~]#
/root/bin/oci setup config
This command provides a walkthrough of creating a valid CLI config file.
The following
links explain where to find the information required by this
script:
User API Signing Key, OCID and Tenancy OCID:
https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#Other
Enter a location for your config [/root/.oci/config]:
Enter a user OCID: ocid1.user.oc1..**************************************
cjgrq
Enter a tenancy OCID: ocid1.tenancy.oc1..***************************************4mq
Enter a region (e.g. ap-chiyoda-1, ap-chuncheon-1,
ap-hyderabad-1, ap-melbourne-1, ap-mumbai-1, ap-osaka-1, ap-seoul-1,
ap-sydney-1, ap-tokyo-1, ca-montreal-1, ca-toronto-1, eu-amsterdam-1,
eu-frankfurt-1, eu-zurich-1, me-dubai-1, me-jeddah-1, sa-saopaulo-1,
uk-cardiff-1, uk-gov-cardiff-1, uk-gov-london-1, uk-london-1, us-ashburn-1,
us-gov-ashburn-1, us-gov-chicago-1, us-gov-phoenix-1, us-langley-1, us-luke-1,
us-phoenix-1, us-sanjose-1): ap-mumbai-1
Do you want to generate a new API Signing RSA key pair? (If
you decline you will be asked to supply the path to an existing key.) [Y/n]:Y
Enter a directory for your keys to be created [/root/.oci]:Press Enter
Enter a name for your key [oci_api_key]:
Public key written to: /root/.oci/oci_api_key_public.pem
Enter a passphrase for your private key (empty for no
passphrase):
Private key written to: /root/.oci/oci_api_key.pem
Fingerprint: 9f:b9:49:35:01:6f:37:38:07:03:5f:c9:24:13:6a:64
Config written to /root/.oci/config
If you haven't
already uploaded your API Signing public key through the
console, follow
the instructions on the page linked below in the section
'How to upload the
public key':
https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#How2
Step 3.
Once configuration is done, go to the path where the
public key has been created in the server.
Add compartment_id in the config file.
[root@server1]# vi /root/.oci/config
compartment_id=ocid1.tenancy.oc1..**********************xhuxifteoynzcrkhheeja5c5vtrv7fhy5wefxq
Upload the file oci_api_key_public.pem into oci.
[root@server1]# cd /root/.oci/
[root@server1]# cat
oci_api_key_public.pem
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp0rjYTvNRnql87jbQCnJ
9ARiS/rb3oCrUziSeAHaDrGwS+mNM0GNdlLCUbLuaZDR+vZHLmGZGD8
hyYPNW1K7dduG3SRsGKjILm75ioeHYFgi1bldPD16lc2emt0q4/OtdDqbMUlqj12
bllYY0cSfVFTJzdnK/Fcb3YGg2UW3Pk3CDdyed+eE2HnGfPauu3Nh84djSkhJ9Yj
aRH4BC0pCPRU/XwCHyfkZpCpQrOEvdkgoaEjF1C8dwNMcIINCcWCNSOTbxvPyma4
2k+wZcmysR3TQBs8+5Ww5+UtcaVUbuPh9RHd1Ch6Eas6woxHxEoaHYlNDS4jL8Sn
XQIDAQAB
-----END PUBLIC KEY-----
Login to OCI console
Under Resources select the option API Keys
Click on Add Public key option and paste the public key
which was generated earlier .
Step 4.
Testing the configuration:-
From the on premise instance run the following command to test
the connectivity.
{
"data": [
{
"fingerprint":
"9f:b9:49:35:01:6f:31:38:07:03:5f:c9:24:13:6a:64",
"inactive-status": null,
"key-id": "ocid1.tenancy.oc1..aaaaaaaaicv6vyqwreetlbdyf4fgghm75wottdro6ito5xg4mq/ocid1.user.oc1..aaaaaaaadluyrev22yy5tbffzysx3wpwerp7y3mkd3oqgkv24q7wycjgrq/9f:b9:49:35:01:6f:37:38:07:03:5f:c9:24:13:6a:64",
"key-value": "-----BEGIN PUBLIC
KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp0rjYTvNRnql87jbQCnJ\n9ARiS/rb3oCrUziSeAHaDrGwS+mNFkF+M5RJeM0GNdlLCUbLuaZDR+vZHLmGZGD8\nhyYPNW1K7dduG3SRsGKjILm75ioeHYFgi1bldPD16lc2emt0q4/OtdDqbMUlqj12\nbllYY0cSfVFTJzdnK/Fcb3YGg2UW3Pk3CDdyed+werewr/XwCHyfkZpCpQrOEvdkgoaEjF1C8dwNMcIINCcWCNSOTbxvPyma4\n2k+wZcmysR3TQBs8+5Ww5+UtcaVUbuPh9RHd1Ch6Eas6woxHxEoaHYlNDS4jL8Sn\nXQIDAQAB\n-----END
PUBLIC KEY-----",
"lifecycle-state": "ACTIVE",
"time-created": "2020-11-16T08:49:24.642000+00:00",
"user-id": "ocid1.user.oc1..aaaaaaaadluyrwer43wps6anbp7y3mkd3oqgkv24q7wycjgrq"
}
]
}
From the above output it shows the connection is successful.
Step 5.
Uploading objects into OCI object store:-
Before uploading the objects ,we need to create an object storage in OCI
Click on Create bucket
Provide details for bucket creation.
Take a note of namespace value.
Now lets upload files from on premise machine.
[root@server1 upload]$mkdir /test/bkp/upload
[root@server1 upload ]touch xyz
Use the following command to upload the objects into object
storage
oci os object put -ns
<object_storage_namespace> -bn <bucket_name> -–file
<file_location>
[root@ccuine23 .oci]# oci os object put -ns bm64se5fa0a -bn
test_bucket --file /test/bkp/upload/xyz
Uploaded xyz
[####################################]
100%
{
"skipped-objects": [],
"upload-failures": {},
"uploaded-objects": {
"xyz": {
"etag": "699c6a97-6124-4da9-b801-01360e99a364",
"last-modified": "Mon, 16 Nov 2020 09:21:03 GMT",
"opc-content-md5": "1B2M2Y8AsgTpgAmY7PhCfg=="
}
}
}
Bulk Upload of all files inside a directory:-
oci os object bulk-upload -ns bm626zuufa0a -bn test_bucket --src-dir /test/bkp/upload
So this concludes the process of uploading files from on prem machine to OCI object storage.
No comments:
Post a Comment