Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Support
  3. cloudron-cli in cron

cloudron-cli in cron

Scheduled Pinned Locked Moved Solved Support
apicli
13 Posts 3 Posters 1.5k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • vladimir.dV Offline
      vladimir.dV Offline
      vladimir.d
      wrote on last edited by girish
      #1

      Hi, need a suggestion how to run cloudron-cli as a cronjob on the cloudron host. Namely we'd like to restore an app backup by cron.
      Considering that the command requires cloudron login as admin first, I doubt it's secure to create and use an admin user without 2FA enabled so I'm thinking to use oathtool for 2FA in console.
      I haven't tried it yet, so not sure it's doable or not.

      Or maybe there is another easier way to perform such admin cloudron tasks without cloudron-cli on the cloudron server?

      Any suggestions very welcomed!

      1 Reply Last reply
      0
      • subvenS Offline
        subvenS Offline
        subven
        wrote on last edited by subven
        #2

        You can create a personal token and pass it to the cron cli command via --token 🙂 Dunno how it works with 2FA enabled but there should be no need to manually log in.

        EDIT: Just noticed that you want to run the cli command on the Cloudron host. The CLI tool is not intended to run on the Cloudron host itself!

        vladimir.dV 1 Reply Last reply
        0
        • girishG Offline
          girishG Offline
          girish
          Staff
          wrote on last edited by
          #3

          Is the use case here to have some sort of a demo app instance that keeps resetting state 🙂 ?

          Instead of using the CLI tool, maybe you can just use the REST API for this. It's just a POST request. Something like:

          curl -X POST -H 'Authorization: Bearer <token>' -d '{"backupId": "id"}' https://my.domain.com/api/v1/apps/<appid>/restore
          
          vladimir.dV 1 Reply Last reply
          0
          • subvenS subven

            You can create a personal token and pass it to the cron cli command via --token 🙂 Dunno how it works with 2FA enabled but there should be no need to manually log in.

            EDIT: Just noticed that you want to run the cli command on the Cloudron host. The CLI tool is not intended to run on the Cloudron host itself!

            vladimir.dV Offline
            vladimir.dV Offline
            vladimir.d
            wrote on last edited by
            #4

            @subven said in cloudron-cli in cron:

            You can create a personal token and pass it to the cron cli command via --token 🙂 Dunno how it works with 2FA enabled but there should be no need to manually log in.

            EDIT: Just noticed that you want to run the cli command on the Cloudron host. The CLI tool is not intended to run on the Cloudron host itself!

            Token seems to work very well.
            What are drawbacks of using CLI tool on the Cloudron host?

            @girish said in cloudron-cli in cron:

            Is the use case here to have some sort of a demo app instance that keeps resetting state 🙂 ?

            Instead of using the CLI tool, maybe you can just use the REST API for this. It's just a POST request. Something like:

            curl -X POST -H 'Authorization: Bearer <token>' -d '{"backupId": "id"}' https://my.domain.com/api/v1/apps/<appid>/restore
            

            Yes, it's for a demo app instance and yes, REST API is a graceful solution.
            I wonder if there is also a REST API call to get appid by CLOUDRON_APP_DOMAIN?

            subvenS 1 Reply Last reply
            0
            • girishG girish

              Is the use case here to have some sort of a demo app instance that keeps resetting state 🙂 ?

              Instead of using the CLI tool, maybe you can just use the REST API for this. It's just a POST request. Something like:

              curl -X POST -H 'Authorization: Bearer <token>' -d '{"backupId": "id"}' https://my.domain.com/api/v1/apps/<appid>/restore
              
              vladimir.dV Offline
              vladimir.dV Offline
              vladimir.d
              wrote on last edited by vladimir.d
              #5

              @girish said in cloudron-cli in cron:

              Is the use case here to have some sort of a demo app instance that keeps resetting state 🙂 ?

              Instead of using the CLI tool, maybe you can just use the REST API for this. It's just a POST request. Something like:

              curl -X POST -H 'Authorization: Bearer <token>' -d '{"backupId": "id"}' https://my.domain.com/api/v1/apps/<appid>/restore
              

              I created a token in the profile and got backupId using the REST API call:

              curl -X GET -H 'Authorization: Bearer <token>' https://my.domain/api/v1/apps/<appid>/backups
              

              I get the following error on the backup restore REST API call:

              {
                "status": "Bad Request",
                "message": "backupId must be non-empty string"
              }
              

              So I'm sure the token and backupId are correct and valid.
              The CLI tool successfully restores the backup copy by the same token and backupId.
              What am I missing?

              girishG 1 Reply Last reply
              0
              • vladimir.dV vladimir.d

                @subven said in cloudron-cli in cron:

                You can create a personal token and pass it to the cron cli command via --token 🙂 Dunno how it works with 2FA enabled but there should be no need to manually log in.

                EDIT: Just noticed that you want to run the cli command on the Cloudron host. The CLI tool is not intended to run on the Cloudron host itself!

                Token seems to work very well.
                What are drawbacks of using CLI tool on the Cloudron host?

                @girish said in cloudron-cli in cron:

                Is the use case here to have some sort of a demo app instance that keeps resetting state 🙂 ?

                Instead of using the CLI tool, maybe you can just use the REST API for this. It's just a POST request. Something like:

                curl -X POST -H 'Authorization: Bearer <token>' -d '{"backupId": "id"}' https://my.domain.com/api/v1/apps/<appid>/restore
                

                Yes, it's for a demo app instance and yes, REST API is a graceful solution.
                I wonder if there is also a REST API call to get appid by CLOUDRON_APP_DOMAIN?

                subvenS Offline
                subvenS Offline
                subven
                wrote on last edited by
                #6

                @vladimir-d said in cloudron-cli in cron:

                I wonder if there is also a REST API call to get appid by CLOUDRON_APP_DOMAIN?

                Take a look at the API documentation for Cloudron ^^

                @vladimir-d said in cloudron-cli in cron:

                What are drawbacks of using CLI tool on the Cloudron host?

                It should be avoided to install anything on the host server manually. Second you get yourself in a situation where you have circular dependency which is never a good thing.

                @vladimir-d said in cloudron-cli in cron:

                The CLI tool successfully restores the backup copy by the same token and backupId.

                You did something like: '{"backupId": "2022-11-11-030000-618/app_archiv.domain.com_v2.2.1"}'?

                vladimir.dV 1 Reply Last reply
                1
                • subvenS subven

                  @vladimir-d said in cloudron-cli in cron:

                  I wonder if there is also a REST API call to get appid by CLOUDRON_APP_DOMAIN?

                  Take a look at the API documentation for Cloudron ^^

                  @vladimir-d said in cloudron-cli in cron:

                  What are drawbacks of using CLI tool on the Cloudron host?

                  It should be avoided to install anything on the host server manually. Second you get yourself in a situation where you have circular dependency which is never a good thing.

                  @vladimir-d said in cloudron-cli in cron:

                  The CLI tool successfully restores the backup copy by the same token and backupId.

                  You did something like: '{"backupId": "2022-11-11-030000-618/app_archiv.domain.com_v2.2.1"}'?

                  vladimir.dV Offline
                  vladimir.dV Offline
                  vladimir.d
                  wrote on last edited by vladimir.d
                  #7

                  @subven said in cloudron-cli in cron:

                  You did something like: '{"backupId": "2022-11-11-030000-618/app_archiv.domain.com_v2.2.1"}'?

                  No, I put Id value from the backup list response, e.g. a backup list response from REST API documentation:

                  {
                    "backups": [
                      {
                        "id": "string",
                        "remotePath": "2022-10-24-060000-679/app_cubby.nebulon.space_v1.0.1",
                        "label": "My important backup",
                        "identifier": "e7d4cc36-9ac0-4f93-8534-62514abe5d9c",
                        "creationTime": 0,
                        "type": "app",
                        "state": "normal",
                        "format": "rsync",
                        "preserveSecs": 604800,
                        "encryptionVersion": "string",
                        "dependsOn": [
                          null
                        ],
                        "manifest": null
                      }
                    ]
                  }
                  

                  Do you mean remotePath value is being used as backupId in the backup restore request?

                  subvenS 1 Reply Last reply
                  0
                  • vladimir.dV vladimir.d

                    @subven said in cloudron-cli in cron:

                    You did something like: '{"backupId": "2022-11-11-030000-618/app_archiv.domain.com_v2.2.1"}'?

                    No, I put Id value from the backup list response, e.g. a backup list response from REST API documentation:

                    {
                      "backups": [
                        {
                          "id": "string",
                          "remotePath": "2022-10-24-060000-679/app_cubby.nebulon.space_v1.0.1",
                          "label": "My important backup",
                          "identifier": "e7d4cc36-9ac0-4f93-8534-62514abe5d9c",
                          "creationTime": 0,
                          "type": "app",
                          "state": "normal",
                          "format": "rsync",
                          "preserveSecs": 604800,
                          "encryptionVersion": "string",
                          "dependsOn": [
                            null
                          ],
                          "manifest": null
                        }
                      ]
                    }
                    

                    Do you mean remotePath value is being used as backupId in the backup restore request?

                    subvenS Offline
                    subvenS Offline
                    subven
                    wrote on last edited by
                    #8

                    @vladimir-d said in cloudron-cli in cron:

                    Do you mean remotePath value is being used as backupId in the backup restore request?

                    Nah just want to make sure you're using the right thing. Do you use the current Cloudron version (v7.3.2)?

                    Here are some examples:

                    Curl (Windows PS)

                    PS C:\Windows\system32> curl.exe -X POST -H 'Authorization: Bearer aheregoesyourmagictokenhehehehhe1' -d "backupId=app_19c44041-367d-4977-a68b-9c6e24326f38_v2.2.1_9439b666029210f32d06c19e7f1af7ed337daa8ba75ed7740236ab53220235b5" https://my.domain.com/api/v1/apps/19c44041-367d-4977-a68b-9c6e24326f38/restore
                    {
                      "taskId": "11075"
                    }
                    

                    CLI tool

                    PS C:\Windows\system32> cloudron restore --app 19c44041-367d-4977-a68b-9c6e24326f38 --backup app_19c44041-367d-4977-a68b-9c6e24326f38_v2.2.1_9439b666029210f32d06c19e7f1af7ed337daa8ba75ed7740236ab53220235b5
                    
                     => Queued
                     => Downloading icon .
                     => Restoring addons .
                     => Wait for health check .
                    
                    App is restored
                    
                    girishG 1 Reply Last reply
                    0
                    • vladimir.dV vladimir.d

                      @girish said in cloudron-cli in cron:

                      Is the use case here to have some sort of a demo app instance that keeps resetting state 🙂 ?

                      Instead of using the CLI tool, maybe you can just use the REST API for this. It's just a POST request. Something like:

                      curl -X POST -H 'Authorization: Bearer <token>' -d '{"backupId": "id"}' https://my.domain.com/api/v1/apps/<appid>/restore
                      

                      I created a token in the profile and got backupId using the REST API call:

                      curl -X GET -H 'Authorization: Bearer <token>' https://my.domain/api/v1/apps/<appid>/backups
                      

                      I get the following error on the backup restore REST API call:

                      {
                        "status": "Bad Request",
                        "message": "backupId must be non-empty string"
                      }
                      

                      So I'm sure the token and backupId are correct and valid.
                      The CLI tool successfully restores the backup copy by the same token and backupId.
                      What am I missing?

                      girishG Offline
                      girishG Offline
                      girish
                      Staff
                      wrote on last edited by girish
                      #9

                      @vladimir-d I think this might be because of the missing Content-Type header (I didn't put that in my original post). Looks like it might not be parsing the input as json.

                      curl -H 'Content-Type: application/json' -X POST -H 'Authorization: Bearer token' https://my.cloudron.domain/api/v1/apps/<appid>/restore -d '{"backupId": "app_219fa028-e694-4b0f-a050-e95de64868cb_v2.25.0_blah" }'
                      
                      1 Reply Last reply
                      0
                      • subvenS subven

                        @vladimir-d said in cloudron-cli in cron:

                        Do you mean remotePath value is being used as backupId in the backup restore request?

                        Nah just want to make sure you're using the right thing. Do you use the current Cloudron version (v7.3.2)?

                        Here are some examples:

                        Curl (Windows PS)

                        PS C:\Windows\system32> curl.exe -X POST -H 'Authorization: Bearer aheregoesyourmagictokenhehehehhe1' -d "backupId=app_19c44041-367d-4977-a68b-9c6e24326f38_v2.2.1_9439b666029210f32d06c19e7f1af7ed337daa8ba75ed7740236ab53220235b5" https://my.domain.com/api/v1/apps/19c44041-367d-4977-a68b-9c6e24326f38/restore
                        {
                          "taskId": "11075"
                        }
                        

                        CLI tool

                        PS C:\Windows\system32> cloudron restore --app 19c44041-367d-4977-a68b-9c6e24326f38 --backup app_19c44041-367d-4977-a68b-9c6e24326f38_v2.2.1_9439b666029210f32d06c19e7f1af7ed337daa8ba75ed7740236ab53220235b5
                        
                         => Queued
                         => Downloading icon .
                         => Restoring addons .
                         => Wait for health check .
                        
                        App is restored
                        
                        girishG Offline
                        girishG Offline
                        girish
                        Staff
                        wrote on last edited by
                        #10

                        @subven said in cloudron-cli in cron:

                        curl.exe -X POST -H 'Authorization: Bearer aheregoesyourmagictokenhehehehhe1' -d "backupId=app_19c44041-367d-4977-a68b-9c6e24326f38_v2.2.1_9439b666029210f32d06c19e7f1af7ed337daa8ba75ed7740236ab53220235b5" https://my.domain.com/api/v1/apps/19c44041-367d-4977-a68b-9c6e24326f38/restore

                        Ah nice, I just tested this and the above works as well. It's using form encoding I guess (which is curl's default?).

                        1 Reply Last reply
                        1
                        • vladimir.dV Offline
                          vladimir.dV Offline
                          vladimir.d
                          wrote on last edited by
                          #11

                          still have no luck.

                          If I add -H 'Content-Type: application/json' to the backup restoring request I get:

                          { "status": "Internal Server Error", "message": "Cannot read properties of null (reading 'manifest')" }
                          

                          I tried to send the request using curl and postman, the response is the same. Cloudron is v7.3.2

                          ps. the CLI tool works well though.

                          girishG 1 Reply Last reply
                          0
                          • vladimir.dV vladimir.d

                            still have no luck.

                            If I add -H 'Content-Type: application/json' to the backup restoring request I get:

                            { "status": "Internal Server Error", "message": "Cannot read properties of null (reading 'manifest')" }
                            

                            I tried to send the request using curl and postman, the response is the same. Cloudron is v7.3.2

                            ps. the CLI tool works well though.

                            girishG Offline
                            girishG Offline
                            girish
                            Staff
                            wrote on last edited by
                            #12

                            @vladimir-d Can you post your entire request? Something else is off.

                            vladimir.dV 1 Reply Last reply
                            0
                            • girishG girish

                              @vladimir-d Can you post your entire request? Something else is off.

                              vladimir.dV Offline
                              vladimir.dV Offline
                              vladimir.d
                              wrote on last edited by vladimir.d
                              #13

                              @girish sorry, a school boy mistake, the Content-Type header did the trick, but I made a typo in the backupId, that's why I got the error.

                              1 Reply Last reply
                              1
                              • girishG girish marked this topic as a question on
                              • girishG girish has marked this topic as solved on
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Bookmarks
                                • Search