grsync

package module
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 10 Imported by: 10

README

grsync — golang rsync wrapper

codecov GoDoc

Repository contains some helpful tools:

  • raw rsync wrapper
  • rsync task — wrapper which provide important information about rsync task: progress, remain items, total items and speed

Task wrapper usage

package main

import (
    "fmt"
    "grsync"
    "time"
)

func main() {
    task := grsync.NewTask(
        "username@server.com:/source/folder",
        "/home/user/destination",
        grsync.RsyncOptions{},
    )

    go func() {
        for {
            state := task.State()
            fmt.Printf(
                "progress: %.2f / rem. %d / tot. %d / sp. %s \n",
                state.Progress,
                state.Remain,
                state.Total,
                state.Speed,
            )
            <- time.After(time.Second)
        }
    }()

    if err := task.Run(); err != nil {
        panic(err)
    }

    fmt.Println("well done")
    fmt.Println(task.Log())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

type Log struct {
	Stderr string `json:"stderr"`
	Stdout string `json:"stdout"`
}

Log contains raw stderr and stdout outputs

type Rsync

type Rsync struct {
	Source      string
	Destination string
	// contains filtered or unexported fields
}

Rsync is wrapper under rsync

func NewRsync

func NewRsync(source, destination string, options RsyncOptions) *Rsync

NewRsync returns task with described options

func (Rsync) Run

func (r Rsync) Run() error

Run start rsync task

func (Rsync) StderrPipe

func (r Rsync) StderrPipe() (io.ReadCloser, error)

StderrPipe returns a pipe that will be connected to the command's standard error when the command starts.

func (Rsync) StdoutPipe

func (r Rsync) StdoutPipe() (io.ReadCloser, error)

StdoutPipe returns a pipe that will be connected to the command's standard output when the command starts.

type RsyncOptions

type RsyncOptions struct {
	// RsyncBinaryPath is a path to the rsync binary; by default just `rsync`
	RsyncBinaryPath string
	// RsyncPath specify the rsync to run on remote machine, e.g `--rsync-path="cd /a/b && rsync"`
	RsyncPath string
	// Verbose increase verbosity
	Verbose bool
	// Quet suppress non-error messages
	Quiet bool
	// Checksum skip based on checksum, not mod-time & size
	Checksum bool
	// Archve is archive mode; equals -rlptgoD (no -H,-A,-X)
	Archive bool
	// Recurse into directories
	Recursive bool
	// Relative option to use relative path names
	Relative bool
	// NoImliedDirs don't send implied dirs with --relative
	NoImpliedDirs bool
	// Update skip files that are newer on the receiver
	Update bool
	// Inplace update destination files in-place
	Inplace bool
	// Append data onto shorter files
	Append bool
	// AppendVerify --append w/old data in file checksum
	AppendVerify bool
	// Dirs transfer directories without recursing
	Dirs bool
	// Links copy symlinks as symlinks
	Links bool
	// CopyLinks transform symlink into referent file/dir
	CopyLinks bool
	// CopyUnsafeLinks only "unsafe" symlinks are transformed
	CopyUnsafeLinks bool
	// SafeLinks ignore symlinks that point outside the tree
	SafeLinks bool
	// CopyDirLinks transform symlink to dir into referent dir
	CopyDirLinks bool
	// KeepDirLinks treat symlinked dir on receiver as dir
	KeepDirLinks bool
	// HardLinks preserve hard links
	HardLinks bool
	// Perms preserve permissions
	Perms bool
	// NoPerms preserve permissions
	NoPerms bool
	// Executability preserve executability
	Executability bool
	// CHMOD affect file and/or directory permissions
	CHMOD os.FileMode
	// Acls preserve ACLs (implies -p)
	ACLs bool
	// XAttrs preserve extended attributes
	XAttrs bool
	// Owner preserve owner (super-user only)
	Owner bool
	// NoOwner prevent copying owner information to destination
	NoOwner bool
	// Group preserve group
	Group bool
	// NoGroup prevent copying group information to destination
	NoGroup bool
	// Devices preserve device files (super-user only)
	Devices bool
	// Specials preserve special files
	Specials bool
	// Times preserve modification times
	Times bool
	// NoTimes prevent copying modification times
	NoTimes bool
	// omit directories from --times
	OmitDirTimes bool
	// Super receiver attempts super-user activities
	Super bool
	// FakeSuper store/recover privileged attrs using xattrs
	FakeSuper bool
	// Sparce handle sparse files efficiently
	Sparse bool
	// DryRun perform a trial run with no changes made
	DryRun bool
	// WholeFile copy files whole (w/o delta-xfer algorithm)
	WholeFile bool
	// OneFileSystem don't cross filesystem boundaries
	OneFileSystem bool
	// BlockSize block-size=SIZE force a fixed checksum block-size
	BlockSize int
	// Rsh -rsh=COMMAND specify the remote shell to use
	Rsh string
	// Existing skip creating new files on receiver
	Existing bool
	// IgnoreExisting skip updating files that exist on receiver
	IgnoreExisting bool
	// RemoveSourceFiles sender removes synchronized files (non-dir)
	RemoveSourceFiles bool
	// Delete delete extraneous files from dest dirs
	Delete bool
	// DeleteBefore receiver deletes before transfer, not during
	DeleteBefore bool
	// DeleteDuring receiver deletes during the transfer
	DeleteDuring bool
	// DeleteDelay find deletions during, delete after
	DeleteDelay bool
	// DeleteAfter receiver deletes after transfer, not during
	DeleteAfter bool
	// DeleteExcluded also delete excluded files from dest dirs
	DeleteExcluded bool
	// IgnoreErrors delete even if there are I/O errors
	IgnoreErrors bool
	// Force deletion of dirs even if not empty
	Force bool
	// MaxDelete max-delete=NUM don't delete more than NUM files
	MaxDelete int
	// MaxSize max-size=SIZE don't transfer any file larger than SIZE
	MaxSize int
	// MinSize don't transfer any file smaller than SIZE
	MinSize int
	// Partial keep partially transferred files
	Partial bool
	// PartialDir partial-dir=DIR
	PartialDir string
	// DelayUpdates put all updated files into place at end
	DelayUpdates bool
	// PruneEmptyDirs prune empty directory chains from file-list
	PruneEmptyDirs bool
	// NumericIDs don't map uid/gid values by user/group name
	NumericIDs bool
	// Timeout timeout=SECONDS set I/O timeout in seconds
	Timeout int
	// Contimeout contimeout=SECONDS set daemon connection timeout in seconds
	Contimeout int
	// IgnoreTimes don't skip files that match size and time
	IgnoreTimes bool
	// SizeOnly skip files that match in size
	SizeOnly bool
	// ModifyWindow modify-window=NUM compare mod-times with reduced accuracy
	ModifyWindow bool
	// TempDir temp-dir=DIR create temporary files in directory DIR
	TempDir string
	// Fuzzy find similar file for basis if no dest file
	Fuzzy bool
	// CompareDest compare-dest=DIR also compare received files relative to DIR
	CompareDest string
	// CopyDest copy-dest=DIR ... and include copies of unchanged files
	CopyDest string
	// LinkDest link-dest=DIR hardlink to files in DIR when unchanged
	LinkDest string
	// Compress file data during the transfer
	Compress bool
	// CompressLevel explicitly set compression level
	CompressLevel int
	// SkipCompress skip-compress=LIST skip compressing files with suffix in LIST
	SkipCompress []string
	// CVSExclude auto-ignore files in the same way CVS does
	CVSExclude bool
	// Stats give some file-transfer stats
	Stats bool
	// HumanReadable output numbers in a human-readable format
	HumanReadable bool
	// Progress show progress during transfer
	Progress bool
	// Read daemon-access password from FILE
	PasswordFile string
	// limit socket I/O bandwidth
	BandwidthLimit int
	// Info
	Info string
	// Exclude --exclude="", exclude remote paths.
	Exclude []string
	// Include --include="", include remote paths.
	Include []string
	// Filter --filter="", include filter rule.
	Filter string
	// Chown --chown="", chown on receipt.
	Chown string

	// ipv4
	IPv4 bool
	// ipv6
	IPv6 bool

	//out-format
	OutFormat bool
}

RsyncOptions for rsync

type State

type State struct {
	Remain   int     `json:"remain"`
	Total    int     `json:"total"`
	Speed    string  `json:"speed"`
	Progress float64 `json:"progress"`
}

State contains information about rsync process

type Task

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

Task is high-level API under rsync

func NewTask

func NewTask(source, destination string, rsyncOptions RsyncOptions) *Task

NewTask returns new rsync task

func (Task) Log

func (t Task) Log() Log

Log return structure which contains raw stderr and stdout outputs

func (*Task) Run

func (t *Task) Run() error

Run starts rsync process with options

func (Task) State

func (t Task) State() State

State returns inforation about rsync processing task

Jump to

Keyboard shortcuts

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