I would like to retrieve some application's logs.
I found that the command cf file
was not available anymore and the plugin cf-download
doesn't work on Diego Architecture.
Is there a way to retrieve files from the cloud foundry by CLI other another method?
Asked
Active
Viewed 6,083 times
3
-
1Possible duplicate of [How to download the app with the CLI from the Swisscom App Cloud?](https://stackoverflow.com/questions/39365778/how-to-download-the-app-with-the-cli-from-the-swisscom-app-cloud) – Sybil Jan 29 '18 at 11:14
-
you can also use `cf ssh` or native SSH client. See https://docs.cloudfoundry.org/devguide/deploy-apps/ssh-apps.html – Sybil Jan 29 '18 at 11:18
-
The use of API didn't work for me the logs were not present. But in the documentation of SSH i found what i was looking for: Application SSH Access without cf CLI. I'll refer it as the solution – jerem0808 Jan 29 '18 at 12:48
2 Answers
2
A simpler albeit uncloudy / hacky solution is to use cf ssh
to transfer via stdout.
For example, if you want to transfer all files directly under /home/vcap/logs
you can do...
Update: Here's the much simpler and faster version without a for loop using only tar
:
cf ssh <APP> -i <INSTANCE> -c 'tar cfz - logs/*.log' | tar xfz - -C .
In my case this transfers 1 GB log files in just under 20 seconds.
Original answer:
#!/bin/sh
mkdir -p logs
for f in $( cf ssh <APP> -i <INSTANCE> -c 'ls logs/*' ); do
cf ssh <APP> -i <INSTANCE> -c "cat $f" > $f
done
In my setup this took about 11 minutes to transfer 1.3GB of log files.
Using gzip
compression brought this down to 5 minutes (replace the line in the for loop):
cf ssh <APP> -i <INSTANCE> -c "cat $f | gzip -c" | gunzip > $f
Pretty sure this can be optimized using tar
and getting rid of the for loop.

zb226
- 9,586
- 6
- 49
- 79
0
The solution is to use SSH without cf CLI
When you are at the step 4) you can use WinSCP (for Windows) to have a graphical interface to navigate in the folders.

jerem0808
- 95
- 1
- 12
-
You cannot download logs by ssh-ing into the container. If you want logs, you should get them thru Loggregator Firehose. If you have access, you can try the cf firehose plugin for cf-cli. – K.AJ Jan 29 '18 at 17:49
-
By log i mean log from the application. And I was able to download them. But i'll check your solution. – jerem0808 Jan 30 '18 at 07:00
-
You should modify your application to log to STDOUT/STDERR. Then your logs will show up in the log stream (i.e. `cf logs`) and you won't need to go into the container to grab them. If you have a third party app that you can't tell to log to STDOUT and you must grab the log files from the container then this is the solution (i.e. SCP/SFTP). – Daniel Mikusa Jan 30 '18 at 14:49