Chris Lu
12 years ago
36 changed files with 466 additions and 622 deletions
-
96weed-fs/src/cmd/dump/main.go
-
1weed-fs/src/cmd/weed/command.go
-
9weed-fs/src/cmd/weed/shell.go
-
2weed-fs/src/pkg/directory/file_id.go
-
2weed-fs/src/pkg/operation/delete_content.go
-
4weed-fs/src/pkg/operation/lookup_volume_id.go
-
2weed-fs/src/pkg/operation/upload_content.go
-
1weed-fs/src/pkg/replication/volume_growth_test.go
-
2weed-fs/src/pkg/sequence/sequence.go
-
20weed-fs/src/pkg/storage/compact_map.go
-
2weed-fs/src/pkg/storage/compact_map_perf_test.go
-
5weed-fs/src/pkg/storage/needle_map.go
-
9weed-fs/src/pkg/storage/needle_read_write.go
-
9weed-fs/src/pkg/storage/store.go
-
53weed-fs/src/pkg/storage/volume.go
-
1weed-fs/src/pkg/storage/volume_id.go
-
3weed-fs/src/pkg/storage/volume_version.go
-
3weed-fs/src/pkg/topology/data_center.go
-
2weed-fs/src/pkg/topology/node_list_test.go
-
3weed-fs/src/pkg/topology/topology_map.go
-
1weed-fs/src/pkg/util/bytes.go
@ -1,96 +0,0 @@ |
|||
// Copyright Tamás Gulácsi 2013 All rights reserved
|
|||
// Use of this source is governed by the same rules as the weed-fs library.
|
|||
// If this would be ambigous, than Apache License 2.0 has to be used.
|
|||
//
|
|||
// dump dumps the files of a volume to tar or unique files.
|
|||
// Each file will have id#mimetype#original_name file format
|
|||
|
|||
package main |
|||
|
|||
import ( |
|||
"archive/tar" |
|||
"bytes" |
|||
"flag" |
|||
"fmt" |
|||
// "io"
|
|||
"log" |
|||
"os" |
|||
"pkg/storage" |
|||
"strings" |
|||
"time" |
|||
) |
|||
|
|||
var ( |
|||
volumePath = flag.String("dir", "/tmp", "volume directory") |
|||
volumeId = flag.Int("id", 0, "volume Id") |
|||
dest = flag.String("out", "-", "output path. Produces tar if path ends with .tar; creates files otherwise.") |
|||
tarFh *tar.Writer |
|||
tarHeader tar.Header |
|||
counter int |
|||
) |
|||
|
|||
func main() { |
|||
var err error |
|||
|
|||
flag.Parse() |
|||
|
|||
if *dest == "-" { |
|||
*dest = "" |
|||
} |
|||
if *dest == "" || strings.HasSuffix(*dest, ".tar") { |
|||
var fh *os.File |
|||
if *dest == "" { |
|||
fh = os.Stdout |
|||
} else { |
|||
if fh, err = os.Create(*dest); err != nil { |
|||
log.Printf("cannot open output tar %s: %s", *dest, err) |
|||
return |
|||
} |
|||
} |
|||
defer fh.Close() |
|||
tarFh = tar.NewWriter(fh) |
|||
defer tarFh.Close() |
|||
t := time.Now() |
|||
tarHeader = tar.Header{Mode: 0644, |
|||
ModTime: t, Uid: os.Getuid(), Gid: os.Getgid(), |
|||
Typeflag: tar.TypeReg, |
|||
AccessTime: t, ChangeTime: t} |
|||
} |
|||
|
|||
v, err := storage.NewVolume(*volumePath, storage.VolumeId(*volumeId), storage.CopyNil) |
|||
if v == nil || v.Version() == 0 || err != nil { |
|||
log.Printf("cannot load volume %d from %s (%s): %s", *volumeId, *volumePath, v, err) |
|||
return |
|||
} |
|||
log.Printf("volume: %s (ver. %d)", v, v.Version()) |
|||
if err := v.WalkValues(walker); err != nil { |
|||
log.Printf("error while walking: %s", err) |
|||
return |
|||
} |
|||
|
|||
log.Printf("%d files written.", counter) |
|||
} |
|||
|
|||
func walker(n *storage.Needle) (err error) { |
|||
// log.Printf("Id=%d Size=%d Name=%s mime=%s", n.Id, n.Size, n.Name, n.Mime)
|
|||
nm := fmt.Sprintf("%d#%s#%s", n.Id, bytes.Replace(n.Mime, []byte{'/'}, []byte{'_'}, -1), n.Name) |
|||
// log.Print(nm)
|
|||
if tarFh != nil { |
|||
tarHeader.Name, tarHeader.Size = nm, int64(len(n.Data)) |
|||
if err = tarFh.WriteHeader(&tarHeader); err != nil { |
|||
return err |
|||
} |
|||
_, err = tarFh.Write(n.Data) |
|||
} else { |
|||
if fh, e := os.Create(*dest + "/" + nm); e != nil { |
|||
return e |
|||
} else { |
|||
defer fh.Close() |
|||
_, err = fh.Write(n.Data) |
|||
} |
|||
} |
|||
if err == nil { |
|||
counter++ |
|||
} |
|||
return |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue