copier

package module
v0.0.0-...-e22e35a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2017 License: MIT Imports: 9 Imported by: 0

README

Copier

Copier is a tool for copying files from damaged disks at low speed. A timeout can be specified to give-up when the file is uncopiable. All copied files are logged with a status.

Copier has been tested on macOS and Windows.

Requirements

  • Golang 1.7.x,1.8.x

Installation

Manual build

Quick mode

go get github.com/mdouchement/copier/cmd

or

  1. Install Go 1.7 or above
  2. Install Glide dependency manager
  • go get -u github.com/Masterminds/glide
  1. Clone this project
  • git clone https://github.com/mdouchement/copier
  1. Fetch dependencies
  • glide install
  1. Build the binary
  • go build -o copier *.go
  1. Install the compiled binary
  • mv copier /usr/bin/copier

Usage

copier -h
  • Generate files list prior to edit it before launch the copy
copier list -o /tmp/tobecopied.txt ~/Documents

Unwanted line can be commented by adding a # at the start of the line.

  • Start the copy
copier copy --speed 1MBps --timeout 1m --from-list /tmp/tobecopied.txt ~/backup

Logging to /Users/mdouchement/backup/copier.log
File /Users/mdouchement/Documents/.DS_Store: already exist
File /Users/mdouchement/Documents/test.pdf
 4.59 MB / 7.13 MB [===================================>----------]  86.81% 1017.16 KB/s 12s

License

MIT

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Documentation

Index

Constants

View Source
const (
	// ERROR logger severity.
	ERROR = iota
	// WARN logger severity.
	WARN
	// INFO logger severity.
	INFO
	// DEBUG logger severity.
	DEBUG
)
View Source
const (
	// Bps Bytes per second
	Bps int = 1 << (10 * (iota))
	// KBps Kilo Bytes per second
	KBps
	// MBps Mega Bytes per second
	MBps
	// GBps Giga Bytes per second
	GBps
)
View Source
const (

	// StatusAlreadyExist - the destination file exist and is more recent.
	StatusAlreadyExist = "already exist"
	// StatusCopied - file is copied.
	StatusCopied = "copied"
	// StatusOverwritten - destination file is overwritten due to older timpstamp or different size.
	StatusOverwritten = "overwritten"
	// StatusFailed - copy has failed.
	StatusFailed = "failed"
)

Variables

This section is empty.

Functions

func Exists

func Exists(path string) bool

Exists checks whether the path exists

func GetBaseDirectory

func GetBaseDirectory(paths []string) (string, error)

GetBaseDirectory return the common path of the given paths.

func GetBasePath

func GetBasePath(input, output string) string

GetBasePath returns the identical part of the given two paths.

func MkdirAll

func MkdirAll(path string)

MkdirAll creates the given directory and its parrents

func MkdirAllWithFilename

func MkdirAllWithFilename(path string)

MkdirAllWithFilename creates all parent directories of the given filepath

func MoreRecent

func MoreRecent(dst, src string) (bool, error)

MoreRecent checks if the dst file is more recent and have the same size of the src file.

func Size

func Size(path string) (int64, error)

Size return the size of the given path.

Types

type Exec

type Exec struct {
	From  string
	To    string
	Speed float64

	Ready chan struct{}
	// contains filtered or unexported fields
}

An Exec copies files at a given ratelimit.

func NewExec

func NewExec(from, to string, speed float64) *Exec

NewExec returns a new Exec.

func NewExecWithContext

func NewExecWithContext(ctx context.Context, from, to string, speed float64) *Exec

NewExecWithContext returns a new Exec with the given ctx.

func (*Exec) Execute

func (e *Exec) Execute() error

Execute starts the copy with a ratelimit.

func (*Exec) Name

func (e *Exec) Name() string

Name returns the filename.

func (*Exec) Reader

func (e *Exec) Reader() *ProxyReader

Reader returns the file reader.

func (*Exec) Size

func (e *Exec) Size() int64

Size returns the file size.

func (*Exec) Status

func (e *Exec) Status() string

Status returns the copy status.

type LogEntry

type LogEntry struct {
	Severity    int
	Status      string
	FilepathSrc string
	FilepathDst string
}

LogEntry contains detials about an Exec log.

type Logger

type Logger struct {
	context.Context
	C chan LogEntry
}

A Logger is an LogEntry centralizer.

func NewLogger

func NewLogger() *Logger

NewLogger returns a new Logger.

func NewLoggerWithContext

func NewLoggerWithContext(ctx context.Context) *Logger

NewLoggerWithContext returns a new Logger with the given ctx.

type ProgressInfo

type ProgressInfo struct {
	Name        string
	Size        int64
	ProxyReader *ProxyReader
	Status      string
}

ProgressInfo handle data for building a progress bar.

type ProxyReader

type ProxyReader struct {
	// contains filtered or unexported fields
}

A ProxyReader is proxified reader.

func NewProxyReader

func NewProxyReader(r io.Reader) *ProxyReader

NewProxyReader new proxyed reader.

func (*ProxyReader) Close

func (r *ProxyReader) Close() (err error)

Close the reader when it implements io.Closer

func (*ProxyReader) Read

func (r *ProxyReader) Read(b []byte) (n int, err error)

Read implements io.Reader

func (*ProxyReader) ReadChunk

func (r *ProxyReader) ReadChunk() <-chan int

ReadChunk returns the number of read bytes for a chunk.

type Supervisor

type Supervisor struct {
	context.Context

	FilePaths     []string
	Destination   string
	ExecTimeout   time.Duration
	Progress      chan ProgressInfo
	Speed         float64
	Retries       int
	RetryInterval time.Duration
	// contains filtered or unexported fields
}

A Supervisor is batch copier handler.

func NewSupervisor

func NewSupervisor(paths []string, destination string) (*Supervisor, error)

NewSupervisor returns a new Supervisor.

func (*Supervisor) Execute

func (s *Supervisor) Execute() error

Execute runs the Supervisor copy batch.

func (*Supervisor) Logger

func (s *Supervisor) Logger() *Logger

Logger returns the Supervisor logger.

func (*Supervisor) Summary

func (s *Supervisor) Summary() map[string]int

Summary returns the summary of an execution.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL