[仅做备份]Openstack 学习记录 (2 Swift 简单尝试SwiftClient)

系统环境:前述所创建的虚拟机,并且swift-client已经安装。参考资料:主要是Openstack Cloud Computing Cookbook。

========================================================================

查看swift的containers:

aaron218@aaron218VM1:~$ swift -V 1.0 -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list
test
test2
test3
㜅댎嘆툎댋鐊툏ऀ㜅Ω툍᠂
嘇蔋鐉Ωऀ☃툏᠂蔊댎嘅鐉鐌嘇
蔈鐊嘈Ω鐌툍蔉☃蔉蔉鐉㜄᠄
蔉᠃ँ鐉㜅㜃㜅댎嘈㜄蔋댎鐉
蔉嘇댍嘆툎ँ嘅ऀ嘇᠂᠃᠂鐌
蔋᠃鐌᠃鐊댎툏蔈᠂鐋蔈툍鐌

(书上是按照2.0来描述的,大概是前面安装的时候并不是相同的版本,另外,-V 参数去掉并不影响结果。)

创建新的containers:

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing post NewContainer

aaron218@aaron218VM1:~$ swift -V 1.0 -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list      
NewContainer
test
test2
test3
㜅댎嘆툎댋鐊툏ऀ㜅Ω툍᠂
嘇蔋鐉Ωऀ☃툏᠂蔊댎嘅鐉鐌嘇
蔈鐊嘈Ω鐌툍蔉☃蔉蔉鐉㜄᠄
蔉᠃ँ鐉㜅㜃㜅댎嘈㜄蔋댎鐉
蔉嘇댍嘆툎ँ嘅ऀ嘇᠂᠃᠂鐌
蔋᠃鐌᠃鐊댎툏蔈᠂鐋蔈툍鐌

(可见已经创建了一个container。对于下面那对乱码,是一些特殊名字的Container,目前还不知道是怎样产生的。UTF-8无法解析。但是可以被删除。)

上传object。(文件上传)

首先在home目录下写入一个文件,test.txt,也可以用dd来创建一个文件。这里按照前面的来作

aaron218@aaron218VM1:~$ nano test.txt        ----然后写入一些内容。

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload test ~/test.txt     ---Upload

aaron218@aaron218VM1:~$ swift -V 1.0 -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list test       ----显示test内的对象。
home/aaron218/test.txt                   ---结果

尝试向其他的container里面上传。

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload NewContainer ~/test.txt
home/aaron218/test.txt

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload NewContainer ~/test2.txt
home/aaron218/test2.txt                  

------传入两个文件

aaron218@aaron218VM1:~$ swift -V 1.0 -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list NewContainer
home/aaron218/test.txt
home/aaron218/test2.txt

--------显示NewContainer里面的Objects

可以使用空格分割向Container里面传入多个对象:

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload NewContainer ~/test2.txt ~/test.txt
home/aaron218/test.txt
home/aaron218/test2.txt

此时,传入同一个Container的重复文件在存储时并不会重复,这一点可以通过查看swift存储状态验证,并且,如果有文件不存在,系统会提示错误,但是不影响其他的文件上传。(目前不了解swift是按照路径和文件名判定重复还是有其他的机制)


上传Object,传入目录:

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload NewContainer ~/bin
home/aaron218/bin/startrest
home/aaron218/bin/remakerings
home/aaron218/bin/startmain
home/aaron218/bin/resetswift

aaron218的bin目录下只有少量的数据,所以直接用bin来测试

aaron218@aaron218VM1:~$ swift -V 1.0 -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list NewContainer                   

home/aaron218/bin/remakerings
home/aaron218/bin/resetswift
home/aaron218/bin/startmain
home/aaron218/bin/startrest
home/aaron218/test.txt
home/aaron218/test2.txt

目录中的内容直接被被识别并创建多个对象,而不是一个包含全部文件的对象。(Swift不能保存原先的文件目录结构?除了以名称区分外)

查看Container的属性:

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat NewContainer
  Account: AUTH_test
Container: NewContainer
  Objects: 6
    Bytes: 1826
 Read ACL: 
Write ACL: 
  Sync To: 
 Sync Key: 
Accept-Ranges: bytes
X-Timestamp: 1355993299.08113
Content-Type: text/plain; charset=utf-8

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat test2
  Account: AUTH_test
Container: test2
  Objects: 0
    Bytes: 0
 Read ACL: 
Write ACL: 
  Sync To: 
 Sync Key: 
Accept-Ranges: bytes
X-Timestamp: 1355991740.38834

stat后面不加Container则是查看全部的信息:

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat
   Account: AUTH_test
Containers: 10
   Objects: 82
     Bytes: 468586

………………

X-Timestamp: 1355893837.75311
Accept-Ranges: bytes
Content-Type: text/plain; charset=utf-8

这个命令也可以用来查看Object信息:

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat NewContainer home/aaron218/bin/startmain
       Account: AUTH_test
     Container: NewContainer
        Object: home/aaron218/bin/startmain
  Content Type: application/octet-stream
Content Length: 35
 Last Modified: Thu, 20 Dec 2012 09:16:46 GMT
          ETag: c94e1c6a1ecba4636fedbabc3a059102
    Meta Mtime: 1355892709.009515
 Accept-Ranges: bytes
   X-Timestamp: 1355995006.52084


文件(对象)的分段传输:

aaron218@aaron218VM1:~/bin/test$ dd if=/dev/zero of=~/example-10M bs=1M count=10     
记录了10+0 的读入
记录了10+0 的写出
10485760字节(10 MB)已复制,0.0224356 秒,467 MB/秒   -------先创建一个“大”文件,10M

aaron218@aaron218VM1:~/bin/test$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload NewContainer -S 1024000 ~/example-10M
home/aaron218/example-10M segment 2
home/aaron218/example-10M segment 7
home/aaron218/example-10M segment 0
home/aaron218/example-10M segment 1
home/aaron218/example-10M segment 8
home/aaron218/example-10M segment 5
home/aaron218/example-10M segment 10
home/aaron218/example-10M segment 3
home/aaron218/example-10M segment 6
home/aaron218/example-10M segment 4
home/aaron218/example-10M segment 9
home/aaron218/example-10M

将文件按照1M每个的方式上传了,注意顺序是不一定的。下面是紧随其后的再次上传:

aaron218@aaron218VM1:~/bin/test$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload NewContainer -S 1024000 ~/example-10M
home/aaron218/example-10M segment 2
home/aaron218/example-10M segment 1
home/aaron218/example-10M segment 0
home/aaron218/example-10M segment 5
home/aaron218/example-10M segment 6
home/aaron218/example-10M segment 7
home/aaron218/example-10M segment 8
home/aaron218/example-10M segment 3
home/aaron218/example-10M segment 4
home/aaron218/example-10M segment 9
home/aaron218/example-10M segment 10
home/aaron218/example-10M

查看Container 的属性:    

aaron218@aaron218VM1:~$ swift -V 1.0 -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list NewContainer
home/aaron218/bin/remakerings
home/aaron218/bin/resetswift
home/aaron218/bin/startmain
home/aaron218/bin/startrest
home/aaron218/example-10M
home/aaron218/test.txt
home/aaron218/test2.txt

但是,查看整个存储的属性,就可以发现,多出了一个新的Container:

aaron218@aaron218VM1:~$ swift -V 1.0 -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list 
NewContainer
NewContainer_segments
test
test2
test3
㜅댎嘆툎댋鐊툏ऀ㜅Ω툍᠂
嘇蔋鐉Ωऀ☃툏᠂蔊댎嘅鐉鐌嘇
蔈鐊嘈Ω鐌툍蔉☃蔉蔉鐉㜄᠄
蔉᠃ँ鐉㜅㜃㜅댎嘈㜄蔋댎鐉
蔉嘇댍嘆툎ँ嘅ऀ嘇᠂᠃᠂鐌
蔋᠃鐌᠃鐊댎툏蔈᠂鐋蔈툍鐌

下面是其中的内容:

aaron218@aaron218VM1:~$ swift -V 1.0 -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list NewContainer_segments
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000000
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000001
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000002
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000003
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000004
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000005
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000006
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000007
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000008
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000009
home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000010

以及该容器的属性:
aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat NewContainer_segments
  Account: AUTH_test
Container: NewContainer_segments
  Objects: 11
    Bytes: 10485760
 Read ACL: 
Write ACL: 
  Sync To: 
 Sync Key: 
Accept-Ranges: bytes
X-Timestamp: 1355999994.17271
Content-Type: text/plain; charset=utf-8

(理论上10M的文件应该是切分为10个,但是由于不是按照1024进位的,所以在后面会多出一个来。如果按照100K切分,最后会得到103个文件……如下,序数为10的文件和序数为9的文件的大小不同,另外在尝试切分100K之后再次尝试切分10个,则分段数据Container里面的数据会完全丢失?使用list看到的是空,使用stat看到里面数据被清零。然后再次按照1M大小切分,则数据又重新正常。

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat NewContainer_segments home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000010
       Account: AUTH_test
     Container: NewContainer_segments
        Object: home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000010
  Content Type: application/octet-stream
Content Length: 245760
 Last Modified: Thu, 20 Dec 2012 10:52:46 GMT
          ETag: 25bfe113bc9eb27b2ed004e8378fdc30
 Accept-Ranges: bytes
   X-Timestamp: 1356000766.42498
aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat NewContainer_segments home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000009
       Account: AUTH_test
     Container: NewContainer_segments
        Object: home/aaron218/example-10M/1355999861.441866/10485760/1024000/00000009
  Content Type: application/octet-stream
Content Length: 1024000
 Last Modified: Thu, 20 Dec 2012 10:52:46 GMT
          ETag: 80ec129d645c70cf0de45b1a5a682235
 Accept-Ranges: bytes
   X-Timestamp: 1356000766.21794

(对象计数似乎也有问题,在上传切分为11块之后,总体的对象计数是87,而再次上传切分为100快之后,总体对象计数仅上升到98,正好增长了11,并且将同一个文件按照不同的剖分上传到不同的Container似乎并不增加总的Object计数?然后首次尝试上传11块,计数器增加了103,再次上传11块,计数器回到只增加1。~这个也有可能是内部的某种特殊计算方式。对于对象保存和计数之间存在的延迟或者其他问题还需要进一步了解


下载对象:

swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing download test        ---下载Container test里面的对象到当前目录下。

aaron218@aaron218VM1:~/test$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing download --all           -----下载所有Container的对象到当前目录,此时前面提到的乱码的Container会导致一些错误,包括文件名过长错误等。

(Swift的下载功能是一个值得探讨的功能)

删除对象和Container:

aaron218@aaron218VM1:~/test$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing delete test home/aaron218/test.txt      删除某一个对象。

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing delete --all     删除全部的Contianer和对象

删除后:

aaron218@aaron218VM1:~$ swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat
   Account: AUTH_test
Containers: 0
   Objects: 0
     Bytes: 0

至此,对于逻辑上来说,所有的数据都删除了,乱码的Container也同时删除,清理出了一个干净的空间为下一次的尝试做准备~







你可能感兴趣的:(存储管理,仅做备份)