Implementing Cloud Storage with OpenStack Swift (2014)
Appendix A. Advanced Features
This appendix provides details on the set of commands that can be run from a Swift CLI session. These commands can be used to perform CRUD operations.
Commands
The commands that can be run from the Swift CLI are list, stat, post, upload, download, and delete. Each command has detailed help, which can be displayed by running the swift command –h command, for example, swift list -h.
List
The list command is used to list the containers for the account or the objects for a container. This subsection describes the usage of the list command.
# swift list <container> -A Auth_URL –U User –K Key --os-username=<auth-user-name> --os-password=<auth-password> --os-tenant-id=<auth-tenant-id> --os-tenant-name=<auth-tenant-name> --os-auth-url=<auth-url> --os-auth-token=<auth-token> --os-storage-url=<storage-url> --os-region-name=<region-name> --os-service-type=<service-type> --os-endpoint-type=<endpoint-type> --prefix=PREFIX
Examples
You can list the containers with size information, using the following commands:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 list --lh
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 list –long
You can list the containers with size information and a prefix of con1 by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 list --lh --prefix con1
You can list the containers with size information and a prefix of con1 in the region regionOne by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 list --lh --prefix con1 --os-region-name=regionOne
Stat
The stat command is used to display information for an account, container, or object. This section describes the usage of the stat command.
# swift stat <container> <object> -A Auth_URL –U User –K Key --os-username=<auth-user-name> --os-password=<auth-password> --os-tenant-id=<auth-tenant-id> --os-tenant-name=<auth-tenant-name> --os-auth-url=<auth-url> --os-auth-token=<auth-token> --os-storage-url=<storage-url> --os-region-name=<region-name> --os-service-type=<service-type> --os-endpoint-type=<endpoint-type>
Examples
Display the metadata of the account by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin: user1 -K t1 stat
Display the metadata of the container2 container by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 stat container2
Display the metadata of the key.txt object in the container3 container by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 stat container3 key.txt
Display the metadata of the account in the regionOne region in long format with totals by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 stat --lh --os-region-name=regionOne
Post
The post command is used to update metadata information for the account, container, or object. This section describes the usage of the post command.
# swift post <container> <object> --read-acl <acl> --write-acl <acl> --meta <name:value> --header <header> -A Auth_URL –U User –K Key --os-username=<auth-user-name> --os-password=<auth-password> --os-tenant-id=<auth-tenant-id> --os-tenant-name=<auth-tenant-name> --os-auth-url=<auth-url> --os-auth-token=<auth-token> --os-storage-url=<storage-url> --os-region-name=<region-name> --os-service-type=<service-type> --os-endpoint-type=<endpoint-type>
Examples
Update the read-acl metadata for the container1 container by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 post container1 --read-acl=account1
Add metadata Size:Large and Color:Blue to the container2 container by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 post container2 -m Size:Large -m Color:Blue
Update the content-type header metadata as text/plain for the container3 container by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 post container3 -H "content-type:text/plain"
Update the read-acl metadata for the container4 container by accessing through the regionOne region:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 post container4 --read-acl=account1 --os-region-name=regionOne
Upload
The upload command is used to upload specified files and directories to the given container. This section describes the usage of the upload command.
# swift upload <container> <file_or_directory> --changed --segment-size <size> --segment-container <container> --leave-segments --header <header> -A Auth_URL –U User –K Key --os-username=<auth-user-name> --os-password=<auth-password> --os-tenant-id=<auth-tenant-id> --os-tenant-name=<auth-tenant-name> --os-auth-url=<auth-url> --os-auth-token=<auth-token> --os-storage-url=<storage-url> --os-region-name=<region-name> --os-service-type=<service-type> --os-endpoint-type=<endpoint-type>
Examples
Upload the key.txt object to the container1 container by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 upload container1 key.txt
Upload multiple objects (key1.txt, key2.txt, and key3.txt) to the container1 container by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 upload container1 key1.txt key2.txt key3.txt
Upload the key.txt object to the container2 container using a segment size (segment-size) of 100 bytes. Swift has an object size limit of 5 GB by default. Larger files can be uploaded by using the segment-size option. The object will be stored as multiple segments in the Swift object store. In this example, each segment created will be of 100 bytes, and there will be several such segments uploaded, based on size of the object. The –changed option is used to upload the file only if this file has changed from when it was last uploaded, as in the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 upload container2 key.txt --changed --segment-size=100
Upload the key.txt object to the container3 container using a segment size (segment-size) of 100 bytes. Also, we explicitly specify the seg_container3 segment folder to where the segments will be uploaded.
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 upload container3 key.txt --segment-size=100 --segment-container=seg_container3
Upload the key.txt object to the container4 container using a segment size (segment-size) of 100 bytes. The use-slo option is specified to create a static large object instead of the default dynamic large object, as shown in the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 upload container4 key.txt --segment-size=100 --use-slo --os-region-name=regionOne
Download
The download command is used to download objects from containers. This section describes the usage of the download command.
# swift download <container> <object> --all --prefix <prefix> --output <out_file> -A Auth_URL –U User –K Key --os-username=<auth-user-name> --os-password=<auth-password> --os-tenant-id=<auth-tenant-id> --os-tenant-name=<auth-tenant-name> --os-auth-url=<auth-url> --os-auth-token=<auth-token> --os-storage-url=<storage-url> --os-region-name=<region-name> --os-service-type=<service-type> --os-endpoint-type=<endpoint-type>
Examples
Download all objects from all the containers by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 download --all
Download all objects with the key prefix from the container1 container by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 download container1 --prefix key
Download the key.txt object from the container1 container by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 download container1 key.txt
Download all objects from all the containers utilizing two threads for object download by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 download --all --object-threads 2 --os-region-name=regionOne
Delete
The delete command is used to delete a container or delete objects within a container. This section describes the usage of the delete command.
# swift delete <container> <object> --all –leave_segments -A Auth_URL –U User –K Key --os-username=<auth-user-name> --os-password=<auth-password> --os-tenant-id=<auth-tenant-id> --os-tenant-name=<auth-tenant-name> --os-auth-url=<auth-url> --os-auth-token=<auth-token> --os-storage-url=<storage-url> --os-region-name=<region-name> --os-service-type=<service-type> --os-endpoint-type=<endpoint-type>
Examples
Delete the key.txt object from the container1 container by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 delete container1 key.txt
Delete all objects from the container2 container, and leave the segments as is, by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 delete container2 --leave-segments
Delete all the objects and all the containers by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 delete --all
Delete all the objects and all the containers utilizing two threads for deleting objects by using the following command:
# swift -V 2.0 -A https://auth.lts2.evault.com/v2.0 -U admin:user1 -K t1 delete --all --object-threads=2 --os-region-name=regionOne