cp

Automatically distribute files across your Shoreline Resources.

The cp command allows you to easily transmit critical files throughout your fleet, even to ephemeral Resources such as Kubernetes (k8s) containers. This technique is potent when you need to distribute and execute custom bash scripts or other critical files across a vast sea of Resources, without the need for manual intervention.

Overview

Copying a file with cp securely transmits the file to the Shoreline backend and stores it as compressed Base64. The file automatically propagates to all targeted Resources, is decompressed to a temporary location, and is finally moved to the destination path.

Copy a File

Copy a file with cp using the following syntax:

cp <source_path> "<resource_query>":<destination_path>

A common technique is to use cp to transfer a script to targeted Resources then remotely execute that script via the Op CLI.

For example, imagine you want to copy a local file called my-script.sh to all shoreline app containers, placing the file in the /tmp/scripts directory.

Use the following cp command to accomplish this.

op>
cp /home/USER/my-script.sh "container | app=\"shoreline\"":/tmp/scripts/my-script.sh
Created file 'file_9fdec4c53a113436383ed5f3dc713481'.

Alternatively, you may also opt to for a named Resource if you want to reuse a common Resource query.

op>
resource apps_shoreline = container | app="shoreline"
Now replace the "<resource_query>" statement in the cp command above with your named Resource.
op>
cp /home/USER/my-script.sh apps_shoreline:/tmp/scripts/my-script.sh

List Files

Use the list files command to return all file objects stored in the Shoreline backend.

op>
list files
NAME                                  | DESTINATION_PATH          | RESOURCE_QUERY
file_9fdec4c53a113436383ed5f3dc713481 | /tmp/scripts/my-script.sh | apps_shoreline
file_5fbc2cc72a7d8a4237374b46d7918615 | /tmp/scripts/other.sh     | apps_shoreline

You can also use filters to help you locate specific files.

op>
list files | name=~"file_9fd"
NAME                                  | DESTINATION_PATH          | RESOURCE_QUERY
file_9fdec4c53a113436383ed5f3dc713481 | /tmp/scripts/my-script.sh | apps_shoreline

Update a File

You can change a handful of properties of an existing file.

  • description - Add a helpful descriptor
op>
file_9fdec4c53a113436383ed5f3dc713481.description = "Resizes PVC"
  • destination_path - Change the remote filesystem path
op>
file_9fdec4c53a113436383ed5f3dc713481.destination_path = "/tmp/other/my-script.sh"
  • resource_query - Change the Resource query
op>
file_9fdec4c53a113436383ed5f3dc713481.resource_query = container | app="bookstore"

Delete a File

To delete an existing file you must use the delete command followed by the file's unique backend name.

op>
delete file_9fdec4c53a113436383ed5f3dc713481

Toggle a File

You can toggle the propagation of a file with the disable and enable commands.

op>
disable file_9fdec4c53a113436383ed5f3dc713481
Updated file 'file_9fdec4c53a113436383ed5f3dc713481'.
op>
enable file_9fdec4c53a113436383ed5f3dc713481
Updated file 'file_9fdec4c53a113436383ed5f3dc713481'.

Useful Shell Commands

List files in the destination_path directory and returns the output to stdout.

op>
container | app="shoreline" | `ls /tmp/scripts/`
ID  | TYPE      | NAME                                  | REGION    | AZ         | STATUS | STDOUT
122 | CONTAINER | test10-cust.shoreline-n27d6.shoreline | us-east-1 | us-east-1b |   0    | my-script.sh
137 | CONTAINER | test10-cust.shoreline-fqvzg.shoreline | us-east-1 | us-east-1b |   0    | my-script.sh
150 | CONTAINER | test10-cust.shoreline-5vcxj.shoreline | us-east-1 | us-east-1a |   0    | my-script.sh

Counts the number of files in the destination_path directory and returns the output to stdout.

op>
container | app="shoreline" | `ls /tmp/scripts* | wc -l`
ID  | TYPE      | NAME                                  | REGION    | AZ         | STATUS | STDOUT
122 | CONTAINER | test10-cust.shoreline-n27d6.shoreline | us-east-1 | us-east-1b |   0    | 1
137 | CONTAINER | test10-cust.shoreline-fqvzg.shoreline | us-east-1 | us-east-1b |   0    | 1
150 | CONTAINER | test10-cust.shoreline-5vcxj.shoreline | us-east-1 | us-east-1a |   0    | 1