slk Use Cases

file version: 08 June 2021

Note

StrongLink uses the term “namespace” or “global namespace” (gns). A “namespace” is comparable to a “directory” or “path” on a common file system.

Obtain Access Token

You have to manually login every 30 days to the StrongLink instance via slk login:

$ slk login
Username: XYZ
Password:
Login Successful

A login token is created after successful login.

Note

slk stores the login token in the home directory of each user (~/.slk/config.json). By default, this file can only accessed by the respective user (permissions: -rw-------/600). However, users should be careful when doing things like chmod 755 * in their home directory. If you assume that your slk login token has been compromized please contact support@dkrz.de .

Check if access token is still valid

$ slk_helpers session
Your session token is valid until Jun 19, 2021, 12:02:27 AM

The date and time until which your login token is valid will be printed.

Archival

Archive one file

We have a file my_file.nc located in /work/bm0146/k204221/important_files and want to archive it onto tape to /ex/am/ple/bm0146/k204221/file_collection

$ slk archive /work/bm0146/k204221/important_files/my_file.nc /ex/am/ple/bm0146/k204221/file_collection

or

$ cd /work/bm0146/k204221/important_files
$ slk archive my_file.nc /ex/am/ple/bm0146/k204221/file_collection

Archive directory recursively

We wish to archive the whole directory /work/bm0146/k204221/important_files onto tape to /ex/am/ple/bm0146/k204221

$ slk archive -R /work/bm0146/k204221/important_files /ex/am/ple/bm0146/k204221

Archive all files stored in a subset of available directories

A model run was performed over 100 years from 1900 to 1999. The results of each model year are stored in a dedicated directory – thus, having folders 1900 until 1999. We want to archive the 1980s only.

$ slk archive /work/bm0146/k204221/model_xyz/output/198? /ex/am/ple/model_xyz/output

Create directory

The slk` has no ``mkdir command yet. slk archive automatically creates the target namespace (= directory) if it does not exist. If you wish to create a namespace or namespace hierarchy in advance (e.g. for a project), you have to options:

  • solution A: use slk_helpers mkdir/slk_helpers mkdirs

  • solution B: create folder structure and dummy files locally are archive them with slk archive1

Solution A: use slk_helpers mkdir/mkdirs

$ slk_helpers mkdir /ex/am/ple/namespaceExists/newNamespace

or

$ slk_helpers mkdirs /ex/am/ple/hierarchy/of/new/namespaces

Solution A: create dummy files and archive them with slk archive

Example: we already have the folder /ex/am/ple/bm0146/k204221 and want to create the folders /ex/am/ple/bm0146/k204221/abc/d01/efg, /ex/am/ple/bm0146/k204221/abc/d02/efg and /ex/am/ple/bm0146/k204221/abc/d03/efg.

$ mkdir -p abc/d01/efg abc/d02/efg abc/d03/efg
$ echo "blub" > abc/d01/efg/dummy.txt
$ echo "blub" > abc/d02/efg/dummy.txt
$ echo "blub" > abc/d03/efg/dummy.txt
$ slk archive -R abc /ex/am/ple/bm0146/k204221
$ rm -rf abc


.. note::

  Archiving empty directories is currently not supported. This was meant to be a feature.

Check checksum of archived file

StrongLink calculates two checksums off each archived file and stores them in the metadata. It compares the stored checksums with the file’s actual checksums at certain stages of the archival and retrieveal process. Commonly, users do not need to check the checksum manually. But, you can if you prefer to do it. If a file has no checksum then it has not been fully archived yet (e.g. the copying is still in progress).

# archive the file
$ slk archive test.nc /ex/am/ple/bm0146/k204221/file_collection
[========================================/] 100% complete. Files archived: 1/1, [5B/5B].

# get the checksum from StrongLink
$ slk_helpers checksum -t sha512 /ex/am/ple/bm0146/k204221/file_collection/test.nc
c7bb8f1a8c4fbf5ff1d8990e0b0859bde7a320f337ca65ea1e79a36423b6d9909da793b26c1c69a711d27867b4f0eae1a4ef0db8483e29f9cda3719208618ffc

# calculate the checksum of your local file
$ sha512sum test.nc
c7bb8f1a8c4fbf5ff1d8990e0b0859bde7a320f337ca65ea1e79a36423b6d9909da793b26c1c69a711d27867b4f0eae1a4ef0db8483e29f9cda3719208618ffc  test.nc

Search files

The slk search command uses a query language that was designed by StrongBox Data Solutions. The query language is described on the StrongLink query language page and in the StrongLink Command Line Interface Guide from page 6 onwards. The syntax of the search requests is not trivial. We will try to provide simpler means to submit common search requests in future.

The output of a search request is NOT the listing of datasets matching the search request, but a SEARCH_ID. This SEARCH_ID can then be used by further slk commands (see below). The SEARCH_ID is assigned globally – e.g. SEARCH_ID 423 exists only once. Each user has access to each SEARCH_ID. Thus, a user can share his/her SEARCH_ID with colleagues. However, the output of slk list SEARCH_ID or retrieval of slk retrieve SEARCH_ID ... depends on the read permissions of the executing user.

Note

Please use ' around your search queries xor (exclusive or) escape all $ in front of operators to prevent their accidental evaluation as bash variables.**

search files by owner / user

We would like to search for all files belonging to user k204221 (id: 25301).

Solution A: using easy-search options

$ slk search -user k204221

Solution B: using RQL search query

A description on how to write the search queries for slk search is provided at the page StrongLink query language and on pages 6 to 8 of the StrongLink Command Line Interface Guide.

$ slk search '{"resources.posix_uid":25301}'

Hint: your ID or that of another user on the DKRZ system can be obtained by using the id command in the Linux shell

$ id $DKRZ_USER

search files larger than 1 MB

We would like to search for all files which are larger than 1 MB.

$ slk search '{"resources.size":{"$gt": 1048576}}'
#  OR
$ slk search "{\"resources.size\":{\"\$gt\": 1048576}}"
#  DO NOT FORGET TO ESCAPE THE $ AS WELL

search file with specific value in field of optional metadata schema

We would like to search for “Max” as value in the metadata field “Producer” of the schema “image”.

$ slk search '{"image.Producer":"Max"}'

search a file by name

We would like to find the file search_me.jpg.

Solution A: using easy-search options

$ slk search -name search_me.jpg

Solution B: using RQL search query

$ slk search "{\"resources.name\": \"search_me.jpg\"}"
Total resources found: 1. Search complete.
Search ID: 23

search files by name using regular expressions

We would like to find all files of the format file_[0-9].nc (like file_1.nc, file_2.nc, …):

$ slk search "{\"resources.name\": {\"\$regex\": \"file_[0-9].nc\"}}"
Total resources found: 3. Search complete.
Search ID: 380

$ slk list 380
Filename       Path                                Size   Mode        User           Group          Modified      Status
file_2.txt     /ex/am/ple/bm0146/k204221/a         11 B   rw-r--r--   k204221        1076           02 Mar 2021
file_1.txt     /ex/am/ple/bm0146/k204221/a/abcd    16 B   rw-r--r--   k204221        1076           02 Mar 2021
file_1.txt     /ex/am/ple/bm0146//k204221/a        11 B   rw-r--r--   k204221        1076           02 Mar 2021
Files 1-3 of 3

search files by one of two owners (logical OR)

We would like to search for all files belonging to user k204216 (id: 24855) or k204221 (id: 25301).

$ slk search '{"$or": [{"resources.posix_uid":24855},{"resources.posix_uid":25301}]}'

Hint: your ID or that of another user on the DKRZ system can be obtained by using the id command in the Linux shell

$ id $DKRZ_USER

search files based on two metadata fields (logical AND)

We would like to search for the file surface_iow_day3d_temp_emep_2003.nc belonging the user k204221

$ slk search '{"$and":[{"resources.name": "surface_iow_day3d_temp_emep_2003.nc"}, {"resources.posix_uid": 25301}]}'
Total resources found: 2. Search complete.
Search ID: 65

search files with specific metadata in a folder recursively

We wish to search recursively in /ex/am/ple/testing for files with Max Mustermann as value in the metadata field document.Author.

$ slk search '{"$and": [{"path": {"$gte": "/ex/am/ple/testing"}}, {"document.Author": "Max Mustermann"}]}'
Total resources found: 314. Search complete.
Search ID: 77

search files with specific metadata in a specific folder without recursion

We wish to search non-recursively in /ex/am/ple/testing for files with Max Mustermann as value in the metadata field document.Author

Currently, the StrongLink query language does only allow the $gte operator to compare a path. But, it is possible to include the resources.parent_id in a search query. If we can obtain the id of the namespace /ex/am/ple/testing, then we can search for files in this namespace. We get the namespace id via the exists command of the slk_helpers.

$ slk_helpers exists /ex/am/ple/testing
Resource found with following id: 618671012

$ slk search '{"$and": [{"resources.parent_id": 618671012}, {"document.Author": "Max Mustermann"}]}'
Total resources found: 12. Search complete.
Search ID: 78

save search ID into shell variable

slk search does not provide a feature out of the box to only print the SEARCH_ID. Currently (might change in future versions), the SEARCH_ID is printed in columns >= 12 of the second row of the text output of slk search. We can use tail and sed to get the second line and extract a number or use tail and cut to get the second line and drop the first 11 characters. Example:

# normal call of slk search
$ slk search '{"resources.posix_uid": 25301}'
Total resources found: 11. Search complete.
Search ID: 466

# get ID using sed:
$ search_id=`slk search '{"resources.posix_uid": 25301}' | tail -n 1 | sed 's/[^0-9]*//g'`
$ echo $search_id
470

# get ID by dropping first 11 characters of the second line
$ search_id=`slk search '{"resources.posix_uid": 25301}' | tail -n 1 | cut -c12-20`
$ echo $search_id
471

# use awk pattern matching to get the correct line and correct column
$ search_id=`slk search '{"resources.posix_uid": 25301}' | awk '/Search ID/ {print($3)}'`
$ echo $search_id
507

Note

This is an example for bash. When using csh, you need to prepend set `` in front of the assignments of the shell variables: ``set search_id=....

using shell variables in searches

We would like to search for all files belonging to user k204221 (id: 25301).

Solution without shell variable:

$ id k204221 -u
25301
$ slk search "{\"resources.posix_uid\":25301}"
Total resources found: 420. Search complete.
Search ID: 474

Solution with shell variable:

$ export uid=`id k204221 -u`
$ slk search "{\"resources.posix_uid\":$uid}"
Total resources found: 420. Search complete.
Search ID: 475

Solution calling another shell programm from within a search query:

$ slk search "{\"resources.posix_uid\":`id k204221 -u`}"
Total resources found: 420. Search complete.
Search ID: 475

Note

The example shell commands are meant for bash. If you are using csh or tcsh they do not work as printed here but have to be adapted.

List files

List files stored in specific namespace

We would like to print all files stored on tape in /ex/am/ple/bm0146/k204221.

$ slk list /ex/am/ple/bm0146/k20422

Recursively list files stored in specific namespace

We would like to print all files stored on tape in /ex/am/ple/bm0146/k204221 and in sub-namespaces.

$ slk list -R /ex/am/ple/bm0146/k204221

List all files of a specific user

We would like to print all files belonging to user k204221 (id: 25301).

First, get the user id (uid) of the user k204221:

$ id k204221
uid=25301(k204221) gid=1076(bm0146) groups=1076(bm0146),1544(dm),200524(ka1209),1603(bk1123)

Second, define a search query:

$ slk search '{"resources.posix_uid":25301}'
Total resources found: 214. Search complete.
Search Id: 9

Third, we print all found files:

$ slk list 9

list search results vs. list the content of a folder

slk search counts all files and namespaces that match the search query that the user is allowed to see/read. slk list search_id prints only files (no namespaces) that the user is allowed to see/read. In contrast, slk list namespace lists files and sub-namespaces in a namespace. The example below clarifies the situation. In the example we assume that the sub-namespace test does not contain any files.

$ slk search '{"path": {"$gte": "/ex/am/ple/testing/testing/test03/test"}}'
Total resources found: 3. Search complete.
Search ID: 856

$ slk list 856
Filename                                  Path                                            Size   Mode        User           Group          Modified      Status
some_file.nc                              /ex/am/ple/testing/testing/test03/test         16.1M   -rw-r--r--  k204221        group1076      01 Apr 2021
Files: 1

$ slk list /ex/am/ple/testing/testing/test03/test
Filename                                  Path                                            Size   Mode        User           Group          Modified      Status
test1                                     /ex/am/ple/testing/testing/test03/test                 drwxr-xr-x  25301          900            06 Apr 2021
test2                                     /ex/am/ple/testing/testing/test03/test                 drwxr-xr-x  25301          900            06 Apr 2021
some_file.nc                              /ex/am/ple/testing/testing/test03/test         16.1M   -rw-r--r--  k204221        group1076      01 Apr 2021
Files: 3

Retrieve files

Retrieve folder stored in specific path

We would like to retrieve all files located in the folder /ex/am/ple/bm0146/k20422/dm/retrieve_us to the current directory.

$ slk retrieve -R /ex/am/ple/bm0146/k20422/dm/retrieve_us .

Retrieve all files of a specific user

We would like to retrieve all files belonging to user k204221 (id: 25301) into /scratch/k/k204221/data. A description on how to write the search queries for slk search is provided at the page StrongLink query language and on pages 6 to 8 of the StrongLink Command Line Interface Guide.

First, get the user id (uid) of the user k204221:

$ id k204221
uid=25301(k204221) gid=1076(bm0146) groups=1076(bm0146),1544(dm),200524(ka1209),1603(bk1123)

Second, define a search query:

$ slk search '{"resources.posix_uid":25301}'
Total resources found: 214. Search complete.
Search Id: 11

Third, we retrieve the files into destination directory:

$ slk retrieve 11 /scratch/k/k204221/data

Manually verify that retrieval was successful

StrongLink calculates two checksums off each archived file and stores them in the metadata. It compares the stored checksums with the file’s actual checksums at certain stages of the archival and retrieveal process. Commonly, users do not need to check the checksum manually. But, you can if you prefer to do it. If a file has no checksum then it has not been fully archived yet (e.g. the copying is still in progress). You should not retrieve such a file.

# retrieve the file
$ slk retrieve /ex/am/ple/bm0146/k204221/file_collection/test.nc .
[========================================-] 100% complete 1/1 files [5B/5B]

# get the checksum of the archived file from StrongLink
$ slk_helpers checksum -t sha512 /ex/am/ple/bm0146/k204221/file_collection/test.nc
c7bb8f1a8c4fbf5ff1d8990e0b0859bde7a320f337ca65ea1e79a36423b6d9909da793b26c1c69a711d27867b4f0eae1a4ef0db8483e29f9cda3719208618ffc

# calculate the checksum of your retrieved file
$ sha512sum test.nc
c7bb8f1a8c4fbf5ff1d8990e0b0859bde7a320f337ca65ea1e79a36423b6d9909da793b26c1c69a711d27867b4f0eae1a4ef0db8483e29f9cda3719208618ffc  test.nc

tag files (set metadata)

Currently (3rd March 2021), it is not possible to set the metadata of single files. Setting the metadata is only possible for all files in a directory or for all files found by a search. However, this will be changed in future releases of the slk.

set one metadata field of all files in one directory

We have archived some very large text files into the namespace /ex/am/ple/bm0146/k204221/texts and, now, want to assign the author’s name (Daniel Neumann) via the metadata field document.Author.

Please see the page Metadata in StrongLink for a list of all metadata schemata and their fields.

$ slk tag /ex/am/ple/bm0146/k204221/text document.Author "Daniel Neumann"
Searching for resources in GNS path: /ex/am/ple/bm0146/k204221/text
Total resources found: 12. Search complete.
Search ID: 26
Add Metadata Job complete, applied to 12 of 12 resources.

set one metadata field of all files of one type belonging one person

We would like to assign the author’s name (Daniel Neumann) via the metadata field document.Author to all text files (mime type: text/plain) by the user k204221.

First, we need to search for the files

$ slk search '{"$and": [{"resources.mimetype":"text/plain"},{"resources.posix_uid":25301}]}'
Total resources found: 359. Search complete.
Search ID: 383

The we apply slk tag on the search result:

$ slk tag 383 document.Author "Daniel Neumann"
Total resources found: 359. Search complete.
[========================================|] 100% complete Metadata applied to 359 of 359 resources. Finishing up......

Change permissions and ownership of files and directories

Grant everyone / all users read access to a directory and its content

We would like to grant all users read access to the namespace /ex/am/ple/bm0146/k20422/public_data recursively. “All users” in this context should mean “the file’s group, all users not in the group and myself”.

$ slk chmod -R a+r /ex/am/ple/bm0146/k20422/public_data

Revoke write access to directory and its content for users of the group

We would like to revoke write access to /ex/am/ple/bm0146/k20422/top_secret_data and its content for all users in the directory’s/file’s group.

$ slk chmod -R g-w /ex/am/ple/bm0146/k20422/top_secret_data

Change the group of a directory and its content

We would like to change the group of the /ex/am/ple/bm0146/k20422/group_data and its content to bm0146. First, we need to obtain the group id of the particular group. Then, we call slk group.

$ gid=`getent group bm0146 | awk -F: '{ print $3 }'`
$ slk group $gid /ex/am/ple/bm0146/k20422/group_data

Get user/group IDs and names

Get user id from user name

# get your user id
$ id -u

# get the id of any user
$ id USER_NAME -u

# get the id of any user
$ getent passwd USER_NAME
#  OR
$ getent passwd USER_NAME | awk -F: '{ print $3 }'

Get user name from user id

# get user name from user id
$ getent passwd USER_ID | awk -F: '{ print $1 }'

Get user id from user name

# get the id of any group
$ getent group GROUP_NAME | awk -F: '{ print $3 }'

# get group names and their ids of all groups of which you are a member
$ id

Get user name from user id

# get group name from group id
$ getent group GROUP_ID | awk -F: '{ print $1 }'

# get group names and their ids of all groups of which you are a member
$ id