4.5 KiB
Go Backup Utility
A simple yet powerful command-line utility written in Go for creating and restoring backups of files, directories, and block devices (like disks). It supports standard gzip compression for files/disks and tar.gz for directories.
The key feature of this tool is the ability to stream backups directly over the network, allowing you to create a backup on one machine and restore it on another without storing intermediate files.
Features
- File, Disk, and Directory Backup: Create backups of individual files, entire directories, or full block devices (e.g.,
/dev/sda). - Network Streaming: Directly stream backups between two machines over a TCP connection.
createacts as a network client, sending data.restoreacts as a network server, receiving data.
- Compression: Uses
gzipfor efficient compression. Directories are archived usingtarbefore compression. - Interactive Progress Bars: Displays a real-time progress bar for both creating and restoring, so you always know the status of the operation.
- Cross-Platform: Written in Go, it can be compiled for Linux, macOS, and Windows.
Installation
To build the utility from source, you need to have Go installed on your system.
- Clone the repository (or download the source code).
- Navigate to the project directory.
- Build the binary:
go build - This will create an executable file named
backup(orbackup.exeon Windows) in the current directory. You can move this file to a directory in your system'sPATH(e.g.,/usr/local/bin) to make it accessible from anywhere.
Usage
The utility has two main commands: create and restore.
Local Backup and Restore
1. Backup a Directory
This will create a tar.gz archive of the specified source directory.
./backup create -s /path/to/source/directory -t /path/to/backup.tar.gz
2. Restore a Directory
This will extract the contents of a tar.gz archive into the specified target directory. If the target directory is omitted, it defaults to the current working directory.
./backup restore -s /path/to/backup.tar.gz -t /path/to/restore/location
3. Backup a File or Disk
This will create a compressed gz file from a source file or a block device.
# Backup a file
./backup create -s /path/to/largefile.log -t /path/to/largefile.log.gz
# Backup a disk partition (use with caution!)
./backup create -s /dev/sdb1 -t /path/to/sdb1_backup.img.gz
4. Restore a File or Disk
This will decompress a .gz file to a target file or write the uncompressed data to a block device.
# Restore a file
./backup restore -s /path/to/largefile.log.gz -t /path/to/restored_largefile.log
# Restore a disk partition (use with extreme caution!)
./backup restore -s /path/to/sdb1_backup.img.gz -t /dev/sdb1
Network Backup and Restore
This is the most powerful feature. It allows you to pipe a backup from a source machine (client) to a target machine (server).
Step 1: On the receiving machine (Server)
First, run the restore command. It will start listening on the specified IP address and port, waiting for a connection. Use 0.0.0.0 to listen on all available network interfaces.
# The server waits for data on port 8080 and will restore it to /mnt/data
./backup restore -s 0.0.0.0:8080 -t /mnt/data
The command will print
Waiting for connection on 0.0.0.0:8080...and will pause until the client connects.
Step 2: On the sending machine (Client)
Now, run the create command, pointing the target (-t) to the IP address and port of the server machine.
# This will back up the /home/user/documents directory and send it directly
# to the server at 192.168.1.100 on port 8080.
./backup create -s /home/user/documents -t 192.168.1.100:8080
The backup process will start, and you will see a progress bar on both the client and server terminals.
Command-line Flags
create:-s, --source: The source file, directory, or disk to back up (required).-t, --target: The target backup file or network address (ip:port) (required).
restore:-s, --source: The source archive file or network address (ip:port) to restore from (required).-t, --target: The target file, disk, or directory. Required for network sources and file/disk restores. Defaults to the current directory for local archive restores.
License
This project is licensed under the MIT License. See the LICENSE file for more details.