caprover / caprover-cli

Command Line Interface for https://github.com/caprover/caprover
72 stars 41 forks source link

Caprover backup using CLI #137

Closed marekbrze closed 1 year ago

marekbrze commented 1 year ago

Hi all,

It would be great to add Caprover Backup action to CLI. It would enable to do scheduled backups along with the docker volume backups.

githubsaturn commented 1 year ago

It's already possible, you can just use a bash script like this:

    API_TOKEN=$(curl $CAPROVER_URL/api/v2/login \
        -H 'x-namespace: captain' \
        -H 'content-type: application/json;charset=UTF-8' \
        --data-raw "{\"password\":\"$CAPROVER_PASSWORD\"}" \
        --compressed --silent | jq -r ".data.token")

    DOWNLOAD_TOKEN=$(curl $CAPROVER_URL/api/v2/user/system/createbackup \
        -H "x-captain-auth: $API_TOKEN" \
        -H 'x-namespace: captain' \
        --data-raw '{"postDownloadFileName":"backup.tar"}' \
        --compressed --silent | jq -r ".data.downloadToken")

    if [ ${#DOWNLOAD_TOKEN} -le 10 ]; then
        echo "DOWNLOAD_TOKEN must be at least 10 char long"
        exit 1
    fi

    wget "$CAPROVER_URL/api/v2/downloads/?namespace=captain&downloadToken=$DOWNLOAD_TOKEN" -O backup.tar
marekbrze commented 1 year ago

@githubsaturn thanks! I added it to the official docs in the pull request above.