MCPcopy Index your code
hub / github.com/benjojo/hot-clone

github.com/benjojo/hot-clone @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
9,750 symbols 21,878 edges 434 files 5,127 documented · 53% updated 9mo ago★ 327
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

hot-clone

This tool allows you to image an actively changing block device. Including the one the rootfs is stored on.

Backup a device

hot-clone uses blktrace, and needs root to enable it. Performance impact seems to be low, though if you are planning to image a highly loaded disk you will want to change the values of:

  -blktrace.bufcount int
        The amount of buffers for blktrace to keep spare (default 16)
  -blktrace.bufsize int
        The size of each buffer for blktrace (default 65536)

To something higher, Ideally not too high since it will add latency to disk change events.

$ sudo ./hot-clone -device /dev/sdb > sdb.hc
[sudo] password for ben: 
2021/09/19 22:36:27 Read 18.0 MiB -- 0 Dirty sectors (0 event drops)
...
2021/09/19 22:39:48 Read 3.7 GiB -- 360 Dirty sectors (0 event drops)
2021/09/19 22:39:49 Catching up 36/360 sectors
2021/09/19 22:39:49 Catching up 72/360 sectors
2021/09/19 22:39:49 Catching up 108/360 sectors
2021/09/19 22:39:49 Catching up 144/360 sectors
2021/09/19 22:39:49 Catching up 180/360 sectors
2021/09/19 22:39:49 Catching up 216/360 sectors
2021/09/19 22:39:49 Catching up 252/360 sectors
2021/09/19 22:39:49 Catching up 288/360 sectors
2021/09/19 22:39:49 Catching up 324/360 sectors
2021/09/19 22:39:49 Catching up 360/360 sectors
2021/09/19 22:39:49 Done

The output it piped to stdout, this is so you can output to a file or a pipe (or directly invoke it from ssh)

Restore a device

You cannot directly restore the output of hot-clone, you will first need to reassemble it. To do this you select -reassemble for the hot-clone output, and -reassemble-output to the device or file you wish to restore to.

$ ./hot-clone -reassemble sdb.hc -reassemble-output sdb.img
2021/09/19 22:40:14 Restoring section (Sector: 0 (len 3959422976 bytes)
$ 

Compile from source code

Golang 1.13 or later is needed to compile. Debian 11 has a reccent enough version, compiling on older Debian will require manually installing golang.

Compiling on Debian 11 and copying the executable to a box running an older OS seems to work (on 64bit PC hardware).

To compile an executable binary:

On the github page, click on code, click on "Download ZIP".

$ unzip -e hot-clone-main.zip
$ cd hot-clone-main
$ go build

See if your executable runs.

$ ./hot-clone --help
  -blktrace.bufcount int
        The amount of buffers for blktrace to keep spare (default 16)
  -blktrace.bufsize int
        The size of each buffer for blktrace (default 65536)
  -device string
        The device you wise to hot-clone
  -print-writes
        print all writes happening
  -reassemble string
        use this hot-clone backup file to restore into a file or block device
  -reassemble-output string
        The path of the file or block device that is going to be restored to
  -verbose
        be extra verbose on whats happening

Distributions

Brief testing indicates that this works on Debian 8, 9, 10 and 11 and Ubuntu 18.10.

Debian 7 does not have the TRACE interface so hot-clone won't work.

Notice

You should avoid using this tool if you can help it. LVM, MD Raid, and DRBD give you far better (and tested) methods to enable system snapshotting/real time backups.

Extension points exported contracts — how you extend this code

Sockaddr (Interface)
Sockaddr represents a socket address. [25 implementers]
sys/unix/syscall_zos_s390x.go
Sockaddr (Interface)
(no doc) [25 implementers]
sys/windows/syscall_windows.go
Sockaddr (Interface)
Sockaddr represents a socket address. [25 implementers]
sys/unix/syscall_unix.go
Log (Interface)
Log interface allows different log implementations to be used. [2 implementers]
sys/windows/svc/debug/log.go
TIPCAddr (Interface)
TIPCAddr is implemented by types that can be used as an address for SockaddrTIPC. It is only implemented by *TIPCSocketA [3 …
sys/unix/syscall_linux.go
Handler (Interface)
Handler is the interface that must be implemented to build Windows service. [1 implementers]
sys/windows/svc/service.go
ResourceIDOrString (Interface)
ResourceIDOrString must be either a ResourceID, to specify a resource or resource type by ID, or a string, to specify a
sys/windows/types_windows.go

Core symbols most depended-on inside this repo

Errno
called by 3410
sys/windows/syscall_windows.go
errnoErr
called by 3237
sys/unix/syscall_unix.go
Syscall
called by 1541
sys/unix/gccgo.go
BytePtrFromString
called by 1220
sys/unix/syscall.go
Signal
called by 1006
sys/unix/syscall_bsd.go
Syscall6
called by 719
sys/unix/gccgo.go
RawSyscall
called by 639
sys/unix/gccgo.go
Addr
called by 402
sys/windows/dll_windows.go

Shape

Function 6,143
Struct 2,205
TypeAlias 849
Method 543
Interface 8
Class 1
FuncType 1

Languages

Go100%
C1%

Modules by API surface

sys/windows/zsyscall_windows.go382 symbols
sys/unix/linux/types.go206 symbols
sys/unix/syscall_linux.go175 symbols
sys/unix/zsyscall_freebsd_arm64.go155 symbols
sys/unix/zsyscall_freebsd_arm.go155 symbols
sys/unix/zsyscall_freebsd_amd64.go155 symbols
sys/unix/zsyscall_freebsd_386.go155 symbols
sys/windows/syscall_windows.go146 symbols
sys/unix/zsyscall_darwin_arm64.go144 symbols
sys/unix/zsyscall_darwin_amd64.go144 symbols
sys/unix/ztypes_linux.go143 symbols
sys/unix/zsyscall_netbsd_arm64.go142 symbols

For agents

$ claude mcp add hot-clone \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact