diskrsync

package module
v0.0.0-...-5d039ae Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: MIT Imports: 11 Imported by: 0

README

diskrsync -- rsync for block devices and disk images

This is a utility for remote backup of disk image files or devices. It uses ssh as a transport and tries to minimise the amount of data transferred. This is done by building a Merkle tree of blake2 hashes on both the source and the target hosts and then traversing the tree only transmitting those blocks where the hashes differ.

It is important that the source file does not change during the process. Typically this would be achieved by creating an LVM snapshot or by freezing the VM if that's not possible.

By default the resulting file is compressed using the spgz library (this can be disabled by using --no-compress flag). Note this only works on filesystems that support punching holes in files like xfs or ext4.

The utility handles sparse files (or just files with a lot of zeros) efficiently. The resulting file will be sparse (even if not compressed).

Size changes are also supported (both shrinks and expansions).

Installation

  1. Install go. Version 1.7 is minimum required but the newer the better. If your distribution lacks the required version, check backports or updates (e.g. for debian or ubuntu) Alternatively, install manually.

  2. Run the following commands:

mkdir workspace
cd workspace
export GOPATH=$(pwd)
go get github.com/dop251/diskrsync/diskrsync
sudo cp -a bin/diskrsync /usr/local/bin
  1. Make sure the binary is copied to the remote machine as well. If the remote machine has a different CPU or OS you may want to use cross-compilation. For example if you are want to build a binary for ARM:
GOARCH=arm go get github.com/dop251/diskrsync/diskrsync
ls -l bin/linux_arm/diskrsync

Usage examples

diskrsync /dev/vg00/lv_snap ruser@backuphost:/mnt/backup/disk

This ensures that /mnt/backup/disk is up-to-date with the LV snapshot. The file will be compressed using spgz and can be recovered using the following command:

spgz -x /mnt/backup/disk /dev/vg00/....
diskrsync --verbose --no-compress --ssh-flags="-i id_file" /var/lib/libvirt/images/disk.img ruser@rbackuphost:/mnt/backup/

This ensures that /mnt/backup/disk.img is up-to-date with the source file.

Documentation

Index

Constants

View Source
const (
	DefTargetBlockSize = 128 * 1024
)

Variables

View Source
var (
	ErrInvalidFormat = errors.New("Invalid data format")
)

Functions

func Source

func Source(reader io.ReadSeeker, size int64, cmdReader io.Reader, cmdWriter io.Writer, useBuffer bool, verbose bool) (err error)

func Target

func Target(writer io.ReadWriteSeeker, size int64, cmdReader io.Reader, cmdWriter io.Writer, useBuffer bool, verbose bool) (err error)

Types

type CountingReader

type CountingReader struct {
	io.Reader
	// contains filtered or unexported fields
}

func (*CountingReader) Count

func (c *CountingReader) Count() int64

func (*CountingReader) Read

func (r *CountingReader) Read(buf []byte) (n int, err error)

type CountingWriteCloser

type CountingWriteCloser struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

func (*CountingWriteCloser) Count

func (c *CountingWriteCloser) Count() int64

func (*CountingWriteCloser) Write

func (r *CountingWriteCloser) Write(buf []byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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