Skip to content

Instantly share code, notes, and snippets.

@tkarpinski
Last active January 7, 2017 21:05
Show Gist options
  • Save tkarpinski/512eb82cfa886f95bb3debc6b84cad83 to your computer and use it in GitHub Desktop.
Save tkarpinski/512eb82cfa886f95bb3debc6b84cad83 to your computer and use it in GitHub Desktop.
Migrate Nearline Storage to Coldline storage for Arq Backup on Google Cloud

###Change Storage class from nearline to coldline - Google Cloud for Arq Backup

  • Upload the storage-class.json to your google cloud console command line (things older than 1 day)
  • run gsutil defstorageclass get gs://{BUCKETNAME}
  • run gsutil defstorageclass set COLDLINE gs://{BUCKETNAME}
  • run gsutil lifecycle get gs://{BUCKETNAME}
  • run gsutil lifecycle set storage-class.json gs://{BUCKETNAME}
SELECT
MIN(cast(time_micros as timestamp)) as mi,
MAX(cast(time_micros as timestamp)) as ma,
COUNT(*) as ct,
cs_bucket,
cs_user_agent
FROM [{PROJECTNAME}:storageanalysis.usage]
--WHERE cs_user_agent = 'GCS Lifecycle Management' -- if you only want Lifecycle events
GROUP BY cs_bucket,cs_user_agent
ORDER BY ma DESC
#Setup instructions, create storageanalysis.usage
# https://cloud.google.com/storage/docs/access-logs
#Enable Logging:
#gsutil logging set on -b gs://{LOGBUCKET} gs://{ARQBUCKET}
# delete old bucket
bq rm -f storageanalysis.usage
#load data for each bucket
bq load --skip_leading_rows=1 storageanalysis.usage \
gs://{LOGBUCKET}/{ARQBUCKET}_usage* \
./cloud_storage_usage_schema_v0.json
{
"lifecycle": {
"rule": [{
"action": {
"type": "SetStorageClass",
"storageClass": "COLDLINE"
},
"condition": {
"createdBefore": "2017-01-01",
"matchesStorageClass": ["NEARLINE"]
}
}]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment