Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to download papertrail logs #1421

Merged
merged 1 commit into from
Feb 23, 2023
Merged

Add script to download papertrail logs #1421

merged 1 commit into from
Feb 23, 2023

Conversation

jjnesbitt
Copy link
Member

This script aids in the download of papertrail logs, as past 2 weeks, we can't easily search papertrail from the UI, and must download the hourly logs. To aid in this, this script will concatenate the logs into one file that can be easily searched.

@yarikoptic
Copy link
Member

FWIW: oh cool! as I have mentioned before, since sometime in 2021 I was downloading them on drogon via this bash script

(base) dandi@drogon:/mnt/backup/dandi/papertrail-logs$ cat fetch.sh 
#!/bin/bash

set -eu

for a in dandi-api dandi-api-staging; do
	echo "Working on $a"
	source .git/$a-secrets.env
	mkdir -p $a
	rm -f $a/archives.json
	curl -sH "X-Papertrail-Token: $PAPERTRAIL_KEY" https://papertrailapp.com/api/v1/archives.json | jq . >| $a/archives.json
	grep filename $a/archives.json | sed -e 's,.*: "\(\(.*\).tsv.*\)".*,\1 \2,g' | while read filename datestamp; do
		d=$a/$(echo $datestamp | sed -e 's,-,/,g' -e 's,/[^/]*$,,g')
		f="$d/${filename//.gz/}"
		if [ ! -e "$f" ]; then
			echo -n "  Fetching archive for $datestamp"
			mkdir -p $d
			curl -L -sH "X-Papertrail-Token: $PAPERTRAIL_KEY" "https://papertrailapp.com/api/v1/archives/$datestamp/download" | gunzip > "$f"
			echo -e "\r  Fetched archive for $datestamp: $(wc -l $f)"	
		fi
	done
done

I will check later if it is the same logs . Meanwhile -- let's merge the PR??

@jjnesbitt
Copy link
Member Author

FWIW: oh cool! as I have mentioned before, since sometime in 2021 I was downloading them on drogon via this bash script

(base) dandi@drogon:/mnt/backup/dandi/papertrail-logs$ cat fetch.sh 
#!/bin/bash

set -eu

for a in dandi-api dandi-api-staging; do
	echo "Working on $a"
	source .git/$a-secrets.env
	mkdir -p $a
	rm -f $a/archives.json
	curl -sH "X-Papertrail-Token: $PAPERTRAIL_KEY" https://papertrailapp.com/api/v1/archives.json | jq . >| $a/archives.json
	grep filename $a/archives.json | sed -e 's,.*: "\(\(.*\).tsv.*\)".*,\1 \2,g' | while read filename datestamp; do
		d=$a/$(echo $datestamp | sed -e 's,-,/,g' -e 's,/[^/]*$,,g')
		f="$d/${filename//.gz/}"
		if [ ! -e "$f" ]; then
			echo -n "  Fetching archive for $datestamp"
			mkdir -p $d
			curl -L -sH "X-Papertrail-Token: $PAPERTRAIL_KEY" "https://papertrailapp.com/api/v1/archives/$datestamp/download" | gunzip > "$f"
			echo -e "\r  Fetched archive for $datestamp: $(wc -l $f)"	
		fi
	done
done

I will check later if it is the same logs . Meanwhile -- let's merge the PR??

Sounds good to me!

@jjnesbitt jjnesbitt merged commit 122c6dd into master Feb 23, 2023
@jjnesbitt jjnesbitt deleted the papertrail-logs branch February 23, 2023 01:29
@dandibot
Copy link
Member

🚀 PR was released in v0.3.19 🚀

@dandibot dandibot added the released This issue/pull request has been released. label Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants