12345678910111213141516171819202122232425262728293031323334353637 |
- #!/bin/bash
- # Load environment variables from .env file
- source .env
- # Export Borg passphrase
- export BORG_PASSPHRASE=$PASSPHRASE
- export BORG_RSH="ssh -i $SSH_KEY -p $SSH_PORT"
- json=`sudo -E borg info "$SERVER_USER@$SERVER_IP:$REPOSITORY" --last 1 --json` || exit 1
- count=`echo "$json" | jq '.archives | length'`
- data=""
- i=0
- while [ $i -lt $count ]; do
- name=`echo "$json" | jq ".archives[$i].name"`
- comment=`echo "$json" | jq ".archives[$i].comment"`
- duration=`echo "$json" | jq ".archives[$i].duration"`
- start=`echo "$json" | jq -r ".archives[$i].start"`
- end=`echo "$json" | jq -r ".archives[$i].end"`
- hostname=`echo "$json" | jq -r ".archives[$i].hostname"`
- compressed_size=`echo "$json" | jq ".archives[$i].stats.compressed_size"`
- deduplicated_size=`echo "$json" | jq ".archives[$i].stats.deduplicated_size"`
- nfiles=`echo "$json" | jq ".archives[$i].stats.nfiles"`
- original_size=`echo "$json" | jq ".archives[$i].stats.original_size"`
- repo_location=`echo "$json" | jq -r '.repository.location'`
- timestamp=`date --date="$start" +"%s"`
- data="info,repo_location=$repo_location,hostname=$hostname name=$name,comment=$comment,duration=$duration,compressed_size=$compressed_size,deduplicated_size=$deduplicated_size,nfiles=$nfiles,original_size=$original_size $timestamp"
- curl --request POST \
- "$INFLUXDB_URL/api/v2/write?org=$INFLUXDB_ORG&bucket=$INFLUXDB_BUCKET&precision=s" \
- --header "Authorization: Token $INFLUXDB_TOKEN" \
- --header "Content-Type: text/plain; charset=utf-8" \
- --header "Accept: application/json" \
- --data-binary "$data"
- i=$(($i+1))
- done
|