Setting up the backup script
You can prepare for using the backup script by setting up a private key for the sftp session and setting environment variables.
Procedure
-
Run the following command to connect to the management subsystem as the API Connect
administrator.
ssh ip_address -l apicadm - Select Yes to continue connecting, and once
connected, get necessary credentials:
sudo -i -
Setup a Private Key for sftp Session.
- Create an RSA SSH key. For example, the following command can be used to generate an
SSH key with the required RSA encryption:
ssh-keygen -t rsa -m pemNote the directory in which the generated
id_rsaandid_rsa.pubfiles reside.The generated key needs to be uploaded to the Backup and Restore Pod by adding the key to the
postgres-backrest-repo-configKubernetes secret. - Use the following command to determine the name of the secret:
kubectl get secrets -n <namespace> | grep postgres-backrest-repo-config | awk '{print $1}'Replace
<namespace>with the namespace where the Management Subsystem resides. If you are using the default namespace, you can omit-n <namespace>. - Use the following command to add the key to the secret:
- MacOS
kubectl patch secret <postgres-backrest-repo-config secret name> \ -p="{\"data\":{\"sftp-key\": \"$(cat <path-to-key>/id_rsa | base64)\"}}"\ -n <namespace> - Linux
kubectl patch secret <postgres-backrest-repo-config secret name> \ -p="{\"data\":{\"sftp-key\": \"$(cat <path-to-key>/id_rsa | base64 -w0)\"}}"\ -n <namespace>Note that on Linux an extra
-w0flag is required to the base64 script to ensure that there are no extra line breaks added to the property.
The SSH key will be automatically uploaded to the Backup and Restore Pod as file
/sshd/sftp-key. This can take a few seconds. - MacOS
- The
id_rsa.pubfile needs to be added to the authorized_keys file, on the sftp server, for the username that the sftp session uses.SSHto the sftp server with the following command:ssh <sftp username>@<sftp server>Enter the password when prompted.
Change to the
.sshdirectory of the sftp user. For example,cd /root/.ssh.Append the contents of the
id_rsa.pubto theauthorized_keysfile.
- Create an RSA SSH key. For example, the following command can be used to generate an
SSH key with the required RSA encryption:
- Complete the following setup steps for the sftp script:
- Determine the name of the Backup and Restore Pod, using the following command:
export POD=`kubectl get pods -n <namespace> | grep backrest-shared-repo | awk '{print $1}'` - Set the following environment parameters either on the client machine or in the
Pod:
export HOST=<sftp server hostname> export DIRECTORY=<sftp backup directory on sftp server> export USERNAME=<sftp session username> export PASSWORD=<sftp session password> # if ssh key is not being used
- Determine the name of the Backup and Restore Pod, using the following command: