---
metadata:
  - name: generator
    content: Diplodoc Platform v5.63.0
alternate:
  - en/cookbook/useful-commands
  - en/datalens/cookbook/useful-commands.md
  - ru/cookbook/useful-commands
  - href: en/cookbook/useful-commands.md
    type: text/markdown
    title: Markdown version
csp:
  - script-src:
      - https://mc.yandex.ru
    img-src:
      - https://mc.yandex.ru
    connect-src:
      - https://mc.yandex.ru
      - wss://mc.yandex.ru
    child-src:
      - 'blob:'
      - https://mc.yandex.ru
    frame-src:
      - 'blob:'
      - https://mc.yandex.ru
    frame-ancestors:
      - 'blob:'
      - https://mc.yandex.ru
canonical: en/cookbook/useful-commands.html
title: Useful commands DataLens On-premises
description: >-
  In this tutorial, you will learn about the essential commands for successfully
  administering DataLens On-premises.
vcsPath: en/cookbook/useful-commands.md
---

# Useful commands

This tutorial contains essential commands for administering DataLens On-premises.

## Getting all logs from all application containers {#total-logging}

```shell
./init.sh --stern .
```

## Collecting logs from a single service {#service-logging}

```shell
./init.sh --stern --tail 100 --no-follow deployment/datalens-enterprise-auth
```

## Getting all the K8s cluster's events within the current namespace {#k8s-events}

```shell
./init.sh --kubectl get events
```

## Deploying on a reduced configuration {#min-install}

Recommended minimum configuration for optimal performance:

```yaml
- vCPUs: 8
- RAM: 16 GB
```

This configuration may also be suitable for deployment:

```yaml
- vCPUs: 4
- RAM: 8 GB
```

You can even further reduce resources, though you will experience performance degradation:

```yaml
- vCPUs: 2
- RAM: 4 GB
```

To override resource allocations for specific services, provide the required values in the `values.yaml` file.

You only need to provide the values you want to override, e.g.:

```yaml
application:
    control_api:
    replicas: 1
    version: '0.29.0'
    maxSurge: 50%
    maxUnavailable: 0
    resources:
        requests:
        cpu: 1
        memory: 512Mi
        limits:
        memory: 1024Mi
    data_api:
    replicas: 1
    version: '0.29.0'
    maxSurge: 50%
    maxUnavailable: 0
    resources:
        requests:
        cpu: 1
        memory: 512Mi
        limits:
        memory: 1024Mi
    ui:
    replicas: 1
    version: '0.95.0'
    maxSurge: 50%
    maxUnavailable: 0
    resources:
        requests:
        cpu: 0.5
        memory: 256Mi
        limits:
        memory: 512Mi
    us:
    replicas: 1
    version: '0.79.0'
    maxSurge: 50%
    maxUnavailable: 0
    resources:
        requests:
        cpu: 0.5
        memory: 512Mi
        limits:
        memory: 1024Mi
    auth:
    replicas: 1
    version: '0.34.0'
    maxSurge: 50%
    maxUnavailable: 0
    resources:
        requests:
        cpu: 1
        memory: 512Mi
        limits:
        memory: 1024Mi
```

The following configuration reduces resources even further:

```shell
application:
    control_api:
    replicas: 1
    version: '0.29.0'
    maxSurge: 50%
    maxUnavailable: 0
    resources:
        requests:
        cpu: 1
        memory: 256Mi
        limits:
        memory: 512Mi
    data_api:
    replicas: 1
    version: '0.29.0'
    maxSurge: 50%
    maxUnavailable: 0
    resources:
        requests:
        cpu: 1
        memory: 512Mi
        limits:
        memory: 1024Mi
    ui:
    replicas: 1
    version: '0.95.0'
    maxSurge: 50%
    maxUnavailable: 0
    resources:
        requests:
        cpu: 0.25
        memory: 256Mi
        limits:
        memory: 512Mi
    us:
    replicas: 1
    version: '0.79.0'
    maxSurge: 50%
    maxUnavailable: 0
    resources:
        requests:
        cpu: 0.5
        memory: 256Mi
        limits:
        memory: 512Mi
    auth:
    replicas: 1
    version: '0.34.0'
    maxSurge: 50%
    maxUnavailable: 0
    resources:
        requests:
        cpu: 1
        memory: 256Mi
        limits:
        memory: 512Mi
```

To apply the specified settings, run the `./init.sh --values ./values.yaml` command.

## Rolling back to a previous release {#rollback}

```shell
export KUBECONFIG="/etc/rancher/k3s/k3s.yaml"

./bin/helm-amd64 rollback datalens-enterprise -n datalens-enterprise
```

## Debugging LDAP integration {#ldap-debug}

```shell
ldapsearch \
-H ldap://localhost:8389 \
-x \
-D cn=admin,dc=example,dc=org \
-w admin \
-b ou=users,dc=example,dc=org \
"(uid=bob)"
```

```shell
ldapsearch \
-H ldap://localhost:8389 \
-x \
-D cn=admin,dc=example,dc=org \
-w admin \
-b ou=groups,dc=example,dc=org \
"(&(objectClass=groupOfNames)(member=uid=bob,ou=users,dc=example,dc=org))"
```

## Generating a new administrator password {#admin-password-new}

```shell
echo ""
echo "Generate DataLens password hash..."

PASSWORD_LENGTH=32

PASSWORD_VALUE=$(openssl rand -base64 "${PASSWORD_LENGTH}" | tr -dc a-zA-Z0-9 | head -c "${PASSWORD_LENGTH}")

SALT=$(openssl rand 16)
SALT_HEX=$(echo -n "${SALT}" | od -A n -t x1 -v | tr -d ' \n')
SALT_BASE64URL=$(echo -n "${SALT}" | base64 | tr '+/' '-_' | tr -d '=')

echo "  new admin password: ${PASSWORD_VALUE}"

KEY_LENGTH=64
COST_ITERATIONS=16384
BLOCK_SIZE=8
PARALLELIZATION=1
MAX_MEMORY_BYTES=33554432

KEY_BASE64URL=$(
  openssl kdf -keylen "${KEY_LENGTH}" \
    -kdfopt "pass:${PASSWORD_VALUE}" -kdfopt "hexsalt:${SALT_HEX}" \
    -kdfopt "n:${COST_ITERATIONS}" -kdfopt "r:${BLOCK_SIZE}" -kdfopt "p:${PARALLELIZATION}" \
    -kdfopt "maxmem_bytes:${MAX_MEMORY_BYTES}" \
    -binary scrypt | base64 | tr '+/' '-_' | tr -d '='
)

PASSWORD_HASH="${SALT_BASE64URL}:${KEY_BASE64URL}"
            
echo "  new hash: ${PASSWORD_HASH}"
```

## Updating the administrator password in the database {#admin-password-update}

```shell
psql \
    --host "${POSTGRES_HOST}" \
    --port "${POSTGRES_PORT}" \
    --username "${POSTGRES_USER_AUTH}" \
    --dbname "${POSTGRES_DB_AUTH}" <<-EOSQL
  UPDATE auth_users SET password = '${PASSWORD_HASH}' WHERE login = 'admin';
EOSQL
```

## `Access denied` authorization error {#access-denied}


1. Check that the secrets are populated correctly:

    ```shell
    secrets.AUTH_TOKEN_PRIVATE_KEY 
    secrets.AUTH_TOKEN_PUBLIC_KEY
    ```

1. If you used the `values.yaml` file deployment mode, you will need to generate these secrets manually.

    Here is an example of the `values.yaml` file:

    ```shell
    KUBECONFIG=~/.kube/config ./init.sh --values ./values.deploy.yaml --ingress-domain <domain> --disable-postgres
    ```

    Key generation command:

    ```shell
    openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096
    ```

## Login loop on successful authorization {#ui-app-endpoint}

* Check the `UI_APP_ENDPOINT` value in the Auth service: the authorization cookie is issued to this value.
* If the user logs in via a different endpoint, an incorrect cookie value will be used during authorization.

## Getting `CONTROL_API_CRYPTO_KEY` from K8s secrets {#k8s-crypto-key}

```shell
./init.sh --kubectl get secret datalens-enterprise-secrets -o jsonpath='{.data.CONTROL_API_CRYPTO_KEY}' | base64 -d; echo
```

The output will remain base64-encoded. This is not an error but the correct base64 key value you need to save.

## Recovering a workbook by its ID {#workbook-id-restore}

```shell
 ./init.sh --kubectl exec -it deploy/datalens-enterprise-us -- node -e "fetch('http://localhost:8080/private/v2/workbooks/<WORKBOOK_ID>/restore',{method:'POST',headers:{'content-type':'application/json','x-us-master-token':process.env.MASTER_TOKEN}}).then(r=>r.json()).then(console.log)"
```

Where `<WORKBOOK_ID>` is the workbook ID.

Getting a list of deleted workbooks:

```shell
./init.sh --pg sh -c 'psql -U "${POSTGRES_USER}" -d "${POSTGRES_DB_US}" -c "SELECT encode_id(workbook_id) AS workbook_id,deleted_at FROM workbooks WHERE deleted_at IS NOT NULL"'
```

Copy and paste the exact command from above. You do not need to fill in any values.

## Results {#results}

You have learned the essential commands for successfully administering DataLens On-premises.
