Search code examples
clickhouseclickhouse-backup

Authentication for clickhouse-backup commands


I have a clickhouse instance running wherein I have installed clickhouse-backup. I've connected to it and have no issues running clickhouse-client with a custom user like this:

clickhouse-client -u fred --password 12345

but when I do a clickhouse-backup tables I get

can't connect to clickhouse: code: 516, message: default: Authentication failed: password is incorrect or there is no user with such name. 

How do I run the command clickhouse-backup tables as my custom user 'fred'?


Solution

  • It needs to define these credentials in config.yml file:

    ..
    clickhouse:
      username: fred              # CLICKHOUSE_USERNAME
      password: 12345             # CLICKHOUSE_PASSWORD
    ..
    

    By default config file is located /etc/clickhouse-backup/config.yml.

    To define custom location pass it in --config param.


    As the alternate way, the required params can be passed through environmental variables. Consider run clickhouse-backup as docker-container:

    # generate a backup plan
    
    sudo docker run --rm -it --network host -v "/var/lib/clickhouse:/var/lib/clickhouse" \
        -e CLICKHOUSE_FREEZE_BY_PART=true \
        -e CLICKHOUSE_USERNAME=user \
        -e CLICKHOUSE_PASSWORD=passw \
        \
        alexakulov/clickhouse-backup:latest create --tables="db.table1_local" "table1 [shard-01]"
    
    
    # start a backup process
    
    sudo docker run --rm -it --network host -v "/var/lib/clickhouse:/var/lib/clickhouse" \
        -e CLICKHOUSE_USERNAME=user \
        -e CLICKHOUSE_PASSWORD=passw \
        -e REMOTE_STORAGE=gcs \
        -e GCS_BUCKET=gcs-clickhouse-backup-bucket \
        -e GCS_CREDENTIALS_JSON='_credentials_json_' \
        \
        alexakulov/clickhouse-backup:latest upload "table1 [shard-01]"
    
    
    # remove the local copy of backup
    
    sudo docker run --rm -it --network host -v "/var/lib/clickhouse:/var/lib/clickhouse" \
        \
        alexakulov/clickhouse-backup:latest delete local "table1 [shard-01]"