mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-01-18 22:43:41 +08:00
add option to output to stdout - patch from Tamás Gulácsi
report file size correctly
This commit is contained in:
parent
030dde227a
commit
84e1a59df7
@ -29,7 +29,7 @@ var cmdExport = &Command{
|
||||
var (
|
||||
exportVolumePath = cmdExport.Flag.String("dir", "/tmp", "input data directory to store volume data files")
|
||||
exportVolumeId = cmdExport.Flag.Int("volumeId", -1, "a volume id. The volume should already exist in the dir. The volume index file should not exist.")
|
||||
dest = cmdExport.Flag.String("o", "", "output tar file name, must ends with .tar")
|
||||
dest = cmdExport.Flag.String("o", "", "output tar file name, must ends with .tar, or just a \"-\" for stdout")
|
||||
tarFh *tar.Writer
|
||||
tarHeader tar.Header
|
||||
)
|
||||
@ -40,14 +40,14 @@ func runExport(cmd *Command, args []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if *dest!="" && !strings.HasSuffix(*dest, ".tar") {
|
||||
fmt.Println("the output file", *dest, "should ends with .tar")
|
||||
return false
|
||||
}
|
||||
var err error
|
||||
if strings.HasSuffix(*dest, ".tar") {
|
||||
if *dest != "" {
|
||||
if *dest != "-" && !strings.HasSuffix(*dest, ".tar") {
|
||||
fmt.Println("the output file", *dest, "should be '-' or end with .tar")
|
||||
return false
|
||||
}
|
||||
var fh *os.File
|
||||
if *dest == "" {
|
||||
if *dest == "-" {
|
||||
fh = os.Stdout
|
||||
} else {
|
||||
if fh, err = os.Create(*dest); err != nil {
|
||||
@ -74,13 +74,16 @@ func runExport(cmd *Command, args []string) bool {
|
||||
|
||||
nm := storage.LoadNeedleMap(indexFile)
|
||||
|
||||
var version storage.Version
|
||||
|
||||
err = storage.ScanVolumeFile(*exportVolumePath, vid, func(superBlock storage.SuperBlock) error {
|
||||
version = superBlock.Version
|
||||
return nil
|
||||
}, func(n *storage.Needle, offset uint32) error {
|
||||
debug("key", n.Id, "offset", offset, "size", n.Size, "disk_size", n.DiskSize(), "gzip", n.IsGzipped())
|
||||
nv, ok := nm.Get(n.Id)
|
||||
if ok && nv.Size > 0 {
|
||||
return walker(vid, n)
|
||||
return walker(vid, n, version)
|
||||
} else {
|
||||
if !ok {
|
||||
debug("This seems deleted", n.Id)
|
||||
@ -96,8 +99,8 @@ func runExport(cmd *Command, args []string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func walker(vid storage.VolumeId, n *storage.Needle) (err error) {
|
||||
nm := fmt.Sprintf("%s/%d#%s", n.Mime, n.Id, n.Name)
|
||||
func walker(vid storage.VolumeId, n *storage.Needle, version storage.Version) (err error) {
|
||||
nm := fmt.Sprintf("%s/%d:%s", n.Mime, n.Id, n.Name)
|
||||
if n.IsGzipped() && path.Ext(nm) != ".gz" {
|
||||
nm = nm + ".gz"
|
||||
}
|
||||
@ -108,10 +111,14 @@ func walker(vid storage.VolumeId, n *storage.Needle) (err error) {
|
||||
}
|
||||
_, err = tarFh.Write(n.Data)
|
||||
} else {
|
||||
size := n.DataSize
|
||||
if version == storage.Version1 {
|
||||
size = n.Size
|
||||
}
|
||||
fmt.Printf("key=%s Name=%s Size=%d gzip=%t mime=%s\n",
|
||||
directory.NewFileId(vid, n.Id, n.Cookie).String(),
|
||||
n.Name,
|
||||
n.DataSize,
|
||||
size,
|
||||
n.IsGzipped(),
|
||||
n.Mime,
|
||||
)
|
||||
|
@ -50,9 +50,9 @@ func runFix(cmd *Command, args []string) bool {
|
||||
if n.Size > 0 {
|
||||
count, pe := nm.Put(n.Id, offset/storage.NeedlePaddingSize, n.Size)
|
||||
debug("saved", count, "with error", pe)
|
||||
}else{
|
||||
debug("skipping deleted file ...")
|
||||
nm.Delete(n.Id)
|
||||
} else {
|
||||
debug("skipping deleted file ...")
|
||||
nm.Delete(n.Id)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user