This script utilizes the PowerShell module, OCI.PSModules.Core which is an interface into Oracle Cloud Infrastructure (OCI) API.
This script can be executed on any device supporting PowerShell Core. Currently only tested on Linux OS.
PS> Get-Help Get-PSOciBootBackup
PS> Get-Help Get-PSOciBootBackup -full
NAME: /home/cadayton/ps/Get-PSOciBootBackup.ps1
SYNOPSIS: PowerShell script for performing a Boot Volume Backup on an Oracle Cloud compute instance
running BTCPayServer application to generate an application consistent backup.
SYNTAX
/home/cadayton/ps/Get-PSOciBootBackup.ps1 [-hostname]
This script utilizes the PowerShell module, OCI.PSModules.Core which is an interface into
Oracle Cloud Infrastructure (OCI) API.
This script can be executed on any device supporting PowerShell Core.
Currently only tested on Linux OS.
The input file, $HOME/OCIinstances.xml xml input file containing a list of OCI instances.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OCIinstances>
<instance displayname="myhost1">
<compartmentId>ocid1.tenancy.oc1..dddddddd6xdoxrnz6fd7ef2ieiwx7wglkcufxml263kjptrc57bqp3bxyhyq</compartmentId>
</instance>
<instance displayname="myhost2">
<compartmentId>ocid1.tenancy.oc1..bbbbbbbb6xdoxrnz6fd7ef2ieiwx7wgltxxxxbm263kjptrc57bqp3b12345</compartmentId>
</instance>
</OCIinstances>
PowerShell Core
Private and Public keys need to be created to access the OCI API
1. mkdir ~/.oci
2. Create Private key. Enter the passphrase when prompted.
openssl genrsa -out ~/.oci/oci_api_key.pem -aes128 2048
3. Remove rwx permissions for group and others on Private key
chmod 600 ~/.oci/oci_api_key.pem
4. Generate public key
openssl rsa -pubout -in ~/.oci/oci_api_key.pem -out ~/.oci/oci_api_key_public.pem
Go to the OCI Web Interface -> User Settings -> API-Keys -> Add-Key
Select option to upload public key option
Copy the contents of the config referenced in the dialog to a file named 'config' in the $HOME/.oci directory.
By default a file, named config needs to be create in the $HOME/.oci directory.
Configuration file example $HOME/.oci/config
[DEFAULT]
user = [your ocid1.user.oc1...]
fingerprint = [your fingerprint]
tenancy = [your ocid1.tenancy.oc1...]
region = [your region]
key_file = [your private key $HOME/.oci/oci_api_key.pem]
pass_phrase = [your private key pass phrase]
SDK document for setting file, config
PS > Get-PSOciBootBackup.ps1 myOCIdisplayname
Process overview
1. Initial step is to decrypt the contents of the $HOME/.oci directory.
2. A ssh console session is then open to the OCI compute instance to stop the BTCPayServer applications.
3. The prior Boot Volume backup is removed.
4. A request is submitted to OCI to perform a manual backup of the Boot volume.
5. Waits for the backup state to change to Creating or Available
6. Removes unencrypted files in the $HOME/.oci directory
7. Restart the BTCPayServer docker processes.
Console Output Example
Creating a boot volume backup for [DISPLAY NAME]
Decrypting files in $HOME/.oci
Decrypting $HOME/.oci/config.gpg to $HOME/.oci/config
Decrypting $HOME/.oci/oci_api_key_public.pem.gpg to $HOME/.oci/oci_api_key_public.pem
Decrypting $HOME/.oci/oci_api_key.pem.gpg to $HOME/.oci/oci_api_key.pem
Stopping BTCPay Server docker processes
In the terminal just started enter the following commands to stop BTCPay Server
sudo su -
cd ~/btcpayserver-docker
./btcpay-down.sh
Once the BTCPay docker instances are stopped
Press Enter to continue the Boot Volume backup process
Boot volume backup requested
Waiting on Backup state to be either Creating or Available
Boot volume backup created: Backup 20230208 [DisplayName] Elapse: 00 min 27 sec State: Creating
Removing unencrypted files in $HOME/.oci
Restarting the BTCpay server docker processes
In the [DISPLAY NAME] console Enter the follow command to start the BTCPay docker processes
./btcpay-up.sh
After your donatation, Contact me (cadayton) using any of the following methods to coordinate getting these scripts.