11 Glacier (Archives)
(require (planet gh/aws:1:=3/glacier)) |
Glacier provides storage for archiving. You can store objects less expensively than using S3. The trade-off is that it is very slow to retreive them.
11.1 Region
Set the region. Defaults to "us-east-1".
11.2 Vaults
procedure
(create-vault name) → (or/c #t exn:fail:aws?)
name : string?
procedure
(delete-vault name) → (or/c #t exn:fail:aws?)
name : string?
procedure
(list-vaults) → jsexpr?
List vaults in a jsexpr?.
> (list-vaults) '(#hasheq((VaultName . "testvault") (CreationDate . "2012-08-30T12:29:37.200Z") (LastInventoryDate . null) (NumberOfArchives . 0) (SizeInBytes . 0) (VaultARN . "arn:aws:glacier:us-east-1:203585791165:vaults/testvault")))
Describe a vault in a jsexpr?.
11.3 Vault notifications
procedure
(set-vault-notifications name sns-topic inventory? archive?) → (or/c #t exn:fail:aws?) name : string? sns-topic : string? inventory? : boolean? archive? : boolean?
11.4 Archives
procedure
(create-archive vault-name archive-description data) → string? vault-name : string? archive-description : string? data : bytes?
Create an archive containing the data and return
its archive ID.
Create an archive with data from a file and return its
archive ID.
procedure
(delete-archive vault-name archive-id) → (or/c #t exn:fail:aws?)
vault-name : string? archive-id : string?
Delete an archive.
11.5 Retrieval jobs
procedure
(retrieve-inventory vault-name job-description [ sns-topic]) → string? vault-name : string? job-description : string? sns-topic : (or/c string? #f) = #f
Initiate a job to retrieve an archive’s inventory, and return the job ID.
procedure
(retrieve-archive vault-name job-description [ sns-topic]) → string? vault-name : string? job-description : string? sns-topic : (or/c string? #f) = #f
Initiate a job to retrieve an archive’s data, and return the job ID.
Get the output of a job. If the Content-Type of the
response is application/json, return the result as a jsexpr?,
otherwise return it as bytes?.
procedure
(get-output-job-to-file vault-name job-id path exists) → boolean? vault-name : string? job-id : string? path : path? exists : (or/c 'error 'append 'update 'replace 'truncate 'truncate/replace)
Get the output of an archive retrieval job and put it in a
file. Return a boolean? whether the output matches its
x-amz-sha256-tree-hash.
11.6 Example: Backup using Glacier and SDB
This example can be found in examples/backup.rkt.
#lang racket |
;; Use Glacier for archival backups, and SDB to store the metadata. |
(require (planet gh/aws/sdb) |
(planet gh/aws/sns) |
(planet gh/aws/glacier) |
(planet gh/http/request)) ;just for seconds->gmt-8601-string |
(define path->archive-domain "examplesBackupPathToArchive") |
(define archive->meta-domain "examplesBackupArchiveToMeta") |
(define vault "examples.backup") |
(define (ensure-assets) |
;; Creating a vault on Glacier is idempotent; harmless to do again. |
(create-vault vault) |
;; Creating a domain on SDB is idempotent; harmless to do again. |
(create-domain path->archive-domain) |
(create-domain archive->meta-domain)) |
(define/contract (archive-file path) |
(path? . -> . void?) |
(define path/string (path->string path)) |
;; Upload to Glacier. |
(printf "~a\nUploading to Amazon Glacier ...\n" path/string) |
(define archive-id (create-archive-from-file vault path)) |
;; Store some metadata on SDB. |
;; |
;; Using the path for SDB's ItemName, store an attribute named |
;; ArchiveId with the Glacier archive ID as the value. Remember that |
;; SDB allows multiple values per attribute, so setting this more |
;; than once will add more values rather than replace. |
(printf "Updating Amazon Simple Database with metadata ...\n") |
(put-attributes path->archive-domain |
path/string |
`([ArchiveId ,archive-id])) |
;; Also store some info about this specific archive. |
(put-attributes archive->meta-domain |
archive-id |
`([Size ,(number->string (file-size path))] |
[Date ,(seconds->gmt-8601-string)] |
[Path ,path/string])) |
(void)) |
(define/contract (archive-directory path [sns-topic #f]) |
((path-string?) (string?) . ->* . void?) |
(printf "Ensuring Amazon SDB and Glacier resources are created ...\n") |
(ensure-assets) |
(printf "Starting archive of all files under ~a ...\n" path) |
(for ([x (in-directory path)]) |
;; Unless a directory or a dot file |
(unless (or (directory-exists? x) |
(equal? #\. (string-ref (path->string x) 0))) |
(archive-file x))) |
(when sns-topic |
(publish sns-topic (format "Archive completed ~a." (seconds->gmt-string)))) |
(void)) |
;; For example let's archive the file in our tests dir. |
(define root-dir |
(path->string (simplify-path (path->complete-path (build-path 'up "tests"))))) |
;; Let's notify to our first SNS topic (if any) |
(define sns-topic (match (list-topics) [(list x rest ...) x][else #f])) |
(archive-directory root-dir sns-topic) |
;; Let's look at the information from SDB |
(select-hash (format "SELECT * FROM ~a" path->archive-domain)) |
(select-hash (format "SELECT * FROM ~a" archive->meta-domain)) |