Using the Cloudron CLI tool (Part 2)
4 min read

Using the Cloudron CLI tool (Part 2)

In my previous post, we saw how the Cloudron CLI tool can be used to manage applications from your terminal.

In this post, we will see how to use the CLI tool to manage the Cloudron server using the cloudron machine command.

Installing Cloudron CLI

On Linux and Mac OS X, you can install the CLI tool on your laptop using the following command:

sudo npm install -g cloudron

As of this writing, the CLI tool does not work on Windows.

You can add the following command to end of your .bashrc or .zshrc for tab completion:

. <(cloudron completion)

Login to Cloudron

The first step is to login to your Cloudron. We will use the demo cloudron to test our commands.

$ cloudron login demo.cloudron.me

Enter credentials for demo.cloudron.me:
Username: cloudron
Password: cloudron
Login successful.

There is an analogous cloudron logout, in case you want to switch to using another Cloudron.

Eventlog

To view the various events on the Cloudron:

$ cloudron machine eventlog

When         Action         Source        Info
-----------  -------------  ------------  ---------------------------------------------------
6 hours ago  backup.finish  girish        Backup finished
6 hours ago  backup.start   girish        Backup started
7 hours ago  backup.finish  girish        Backup finished
7 hours ago  backup.start   girish        Backup started
7 hours ago  app.login      ldap          App 6b6dc7d6-...-10b879ab1533 logged in
7 hours ago  user.login     ca3117eb...   User uid-...-7ed3d1825832 logged in
7 hours ago  user.login     ca3117eb...   User uid-...-7ed3d1825832 logged in
7 hours ago  user.login     ca3117eb...   User uid-...-7ed3d1825832 logged in
7 hours ago  app.install    girish        App org.owncloud.cloudronapp@0.10.1 installed at oc
7 hours ago  app.install    girish        App org.ghost.cloudronapp@0.4.0 installed at ghost

View Info

To view DNS and Backup information, including the backup encryption key:

$ cloudron machine info

Cloudron cloudron.info info:

 Appstore:             https://api.cloudron.io
 Version:              0.103.1
 Provider:             digitalocean

Backup config:

 provider:             filesystem
 backupFolder:         /var/backups
 key:

DNS config:

 provider:             route53
 accessKeyId:          AKIAI0SBYOQVT6CUHNWQ
 secretAccessKey:      <snipped>
 region:               us-east-1
 endpoint:             null

Server Logs

To view logs use the cloudron machine logs command:

$ cloudron machine logs
Mar 08 03:10:04 my node[1726]: Box GET /api/v1/apps 304 17.428 ms - -
Mar 08 03:10:04 my node[1726]: Box GET /api/v1/cloudron/config 304 19.167 ms - -
Mar 08 03:10:04 my node[1726]: Box GET /api/v1/profile 304 8.818 ms - -

Mar 08 03:10:09 my node[1726]: Box GET /api/v1/apps 304 6.579 ms - -
Mar 08 03:10:09 my node[1726]: Box GET /api/v1/cloudron/config 304 9.266 ms - -
Mar 08 03:10:09 my node[1726]: Box GET /api/v1/profile 304 8.054 ms - -
Mar 08 03:10:11 my dockerd[1644]: 172.18.0.1 - - [08/Mar/2017:03:10:11 +0000] "GET / HTTP/1.1" 301 62 "-" "node-superagent/1.8.5"
Mar 08 03:10:11 my dockerd[1644]: 172.18.0.1 - - [08/Mar/2017:03:10:11 +0000] "GET / HTTP/1.1" 302 969 "-" "node-superagent/1.8.5"
Mar 08 03:10:11 my node[1726]: box:apphealthmonitor apps alive: [ghost|org.ghost.cloudronapp, oc|org.owncloud.cloudronapp]
Mar 08 03:10:14 my node[1726]: Box GET /api/v1/apps 304 6.384 ms - -
Mar 08 03:10:14 my node[1726]: Box GET /api/v1/cloudron/config 304 4.728 ms - -
Mar 08 03:10:14 my node[1726]: Box GET /api/v1/profile 304 3.337 ms - -

Managing server backups

Cloudron backups can be used to upgrade, restore and migrate servers easily. A complete server backup consists of two parts:

Platform data - This contains the platform database (app list, users & groups and other settings) and the TLS certificates. When the mail server is enabled, all mailboxes are part of this backup as well.

App data - One file for each installed app.

The CLI tool makes it easy to create, list and download server backups.

Create a backup

To create a complete server backup at this instant (note that backups are created automatically every night):

$ cloudron machine backup create
Waiting for backup to finish......
Backup successful

Listing backups

To list the Cloudron backups:

$ cloudron machine backup list

Id                                                        Creation Time             Version
--------------------------------------------------------  ------------------------  -------
2017-03-08-031910-383/box_2017-03-08-480_v0.103.1.tar.gz  Tue Mar 07 2017 19:19:15  0.103.1
2017-03-07-211336-653/box_2017-03-07-697_v0.103.1.tar.gz  Tue Mar 07 2017 13:13:41  0.103.1
2017-03-07-201237-649/box_2017-03-07-237_v0.103.1.tar.gz  Tue Mar 07 2017 12:12:43  0.103.1

Downloading backup

To download the backups:

$ cloudron machine backup download --decrypt 2017-03-08-031910-383/box_2017-03-08-480_v0.103.1-pre.0.tar.gz

Downloading backups:

2017-03-08-031910-383/box_2017-03-08-480_v0.103.1-pre.0.tar.gz
[================================================================================] 100%: 0.0s
2017-03-08-031910-383/app_6b6dc7d6-0aba-4e8e-a3f8-10b879ab1533_2017-03-08-398_v0.4.0.tar.gz
[================================================================================] 100%: 0.0s
2017-03-08-031910-383/app_ca3117eb-0b1b-4530-8a95-5e6f720f7d47_2017-03-08-355_v0.10.1.tar.gz
[================================================================================] 100%: 0.0s

If you download the encrypted backups, you can decrypt them using openssl aes-256-cbc -d -pass "pass:$pass" where $pass is the backup encryption key. You can then unpack the backup using tar zxvf <backup.tar.gz>.

We will see in a future post how you can migrate your Cloudron from one server to another easily using these backups.

Summary

The Cloudron CLI tool can be used to do various server related tasks on the Cloudron. To explore the CLI tool further, run cloudron machine help.