11 Glacier (Archives)
(require aws/glacier) | package: aws |
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
parameter
(num-threads) → exact-nonnegative-integer?
(num-threads v) → void? v : exact-nonnegative-integer?
Set the number of threads to use for multipart uploads. Defaults to 8.
A value of 0 will cause deadlock when an upload is attempted.
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.
procedure
(create-archive-from-port vault-name port description [ #:part-size part-size]) → string? vault-name : string? port : input-port? description : string? part-size : exact-nonnegative-integer? = (* 1024 1024)
Create an archive with data from a port and return its
archive ID.
Data is uploaded part-size bytes at a time, where part-size is a power of two no smaller than 1048576 (1MB) and no larger than 4294967296 (4GB).
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 aws/sdb |
aws/sns |
aws/glacier |
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)) |