9 stable releases
Uses new Rust 2024
new 2.1.6 | Mar 12, 2025 |
---|---|
2.0.2 | Mar 7, 2025 |
1.6.0 | Mar 5, 2025 |
0.2.1 | Feb 27, 2025 |
#135 in Development tools
1,120 downloads per month
160KB
3.5K
SLoC
Docker Container Data Backup Tool
A command-line tool for backing up and restoring Docker container data.
Key Features
- Backs up and restores Docker container data volumes.
- Supports both command-line arguments and interactive operations.
- Employs XZ compression algorithm for efficient compression.
- Offers command-line completion for Bash, Zsh, Fish, and PowerShell.
Supports custom configuration files.
Installation
Ensure you have the Rust toolchain installed on your system, then execute:
# Install rdbkp2
cargo install rdbkp2
# Create symbolic link to enable sudo rdbkp2 ... usage
# sudo ln -s $(where rdbkp2) /usr/local/bin/rdbkp2 # Create a symbolic link for rdbkp2 to /usr/local/bin/rdbkp2 to enable sudo rdbkp2 ... usage
rdbkp2 link install # Use this command to replace manual symbolic link creation above
# Check for updates
rdbkp2 update
# Uninstall rdbkp2
rdbkp2 uninstall
Usage
Listing Available Containers
rdbkp2 list
Backing Up Container Data
[!TIP] The default backup directory is selected based on the following priority:
- $APPDATA/rdbkp2 (Windows) or ~/.local/share/rdbkp2 (Unix)
- $HOME/rdbkp2
- ./rdbkp2 (current directory)
Interactive Mode:
rdbkp2 backup -i
Command-line Mode:
rdbkp2 backup -c container_name -o /path/to/backup/dir
Restoring Container Data
Interactive Mode:
rdbkp2 restore -i
Command-line Mode:
rdbkp2 restore -c container_name -f /path/to/backup/file
Create/Remove Symbol-link for program
rdbkp2 link install # create the symbol-link at /usr/local/bin/rdbkp2
rdbkp2 link uninstall # remove the symbol-link at /usr/local/bin/rdbkp2
Command-Line Completion
Generate command-line completion scripts for various shells:
# Generate Bash completion script
rdbkp2 completions bash > ~/.local/share/bash-completion/completions/rdbkp2
# Generate Zsh completion script
rdbkp2 completions zsh > ~/.zsh/_rdbkp2
# Generate Fish completion script
rdbkp2 completions fish > ~/.config/fish/completions/rdbkp2.fish
# Generate PowerShell completion script
# Windows PowerShell
mkdir -p $PROFILE\..\Completions
rdbkp2 completions powershell > $PROFILE\..\Completions\rdbkp2.ps1
Enabling Completion Functionality
Bash
Add the following lines to your ~/.bashrc
or ~/.bash_profile
:
source ~/.local/share/bash-completion/completions/rdbkp2
Zsh
After placing the completion script in the correct location, ensure completion is enabled in your ~/.zshrc
:
autoload -Uz compinit
compinit
Fish
Fish shell automatically loads completion scripts from the ~/.config/fish/completions
directory. No additional configuration is needed.
PowerShell
Add the following line to your PowerShell profile:
. $PROFILE\..\Completions\rdbkp2.ps1
Command-Line Arguments
Common Arguments
Argument | Description | Default Value |
---|---|---|
-y, --yes |
Automatic confirmation prompt | false |
-i, --interactive |
Use interactive mode | true |
-v, --verbose |
Display detailed logs | false |
-t, --timeout |
Container stop timeout (seconds) | 30 |
-e, --exclude |
Exclusion patterns | ".git,node_modules,target" |
-r, --restart |
Restart container after operation | false |
-l, --lang |
Language (zh-CN/en/ja/ko/es/fr/de/it) | zh-CN |
Backup Command (backup
)
Argument | Description |
---|---|
-c, --container |
Container name or ID |
-f, --file |
Path to file(s) or directory(s) to back up |
-o, --output |
Output directory |
Inherited from common arguments | |
-y, --yes |
Automatic confirmation prompt |
-i, --interactive |
Use interactive mode |
-r, --restart |
Restart the container after operation |
-t, --timeout |
Timeout for stopping the container (seconds) |
-e, --exclude |
Exclusion patterns |
-l, --lang |
Language (zh-CN/en/ja/ko/es/fr/de/it) |
Restore Command (restore
)
[!CAUTION] 💖 Caution: Restoring Docker container bound volumes requires Administrator privileges.
✅ Please run [program] assudo
/Run as Administrator
.
Argument | Description |
---|---|
-c, --container |
Container name or ID |
-f, --file |
Path to backup file (compressed archive) |
-o, --output |
Output directory |
Inherited from common arguments | |
-y, --yes |
Automatic confirmation prompt |
-i, --interactive |
Use interactive mode |
-r, --restart |
Restart container after operation |
-t, --timeout |
Container stop timeout (seconds) |
-e, --exclude |
|
-l, --lang |
Language (zh-CN/en/ja/ko/es/fr/de/it) |
List Command (list
)
No arguments. Displays all available containers.
Completions Command (completions
)
shell
: Specifies the shell type (bash/zsh/fish/powershell)
Link SubCommand (Link install/uninstall
)
[!CAUTION] 💖 Caution: Install soft-symbol-link requires Administrator privileges.
Argument | Description |
---|---|
Inherited from common arguments | |
-y, --yes |
Automatic confirmation prompt |
-l, --lang |
Language (zh-CN/en/ja/ko/es/fr/de/it) |
Important Notes
- When using the Restore function, ensure you operate with
sudo
/ Administrator privileges.- This permission is required for write operations when changing and overwriting Docker container-mounted volumes.
- Ensure sufficient disk space is available for backups.
- It is recommended to back up your current data before restoring.
- You need to have permissions to access the Docker daemon.
- Windows users need to ensure Docker Desktop is running.
Acknowledgments
Library Name | Version | Purpose Description | Link |
---|---|---|---|
clap | 4.5.1 | CLI argument parsing and construction | Crates.io |
dialoguer | 0.11.0 | CLI interactive dialogue tool | Crates.io |
bollard | 0.18 | Docker API client (supports SSL) | Crates.io |
toml | 0.8.10 | TOML format configuration file parsing | Crates.io |
serde | 1.0 | Data serialization/deserialization (with derive support) | Crates.io |
tar | 0.4.40 | TAR compression/decompression | Crates.io |
xz2 | 0.1.7 | XZ compression/decompression | Crates.io |
anyhow | 1.0.80 | Error handling and propagation | Crates.io |
thiserror | 2 | Custom error type definition | Crates.io |
tokio | 1.44 | Asynchronous runtime (with full features) | Crates.io |
tracing | 0.1.40 | Log tracing system | Crates.io |
tracing-subscriber | 0.3.18 | Log subscription and formatting (with environment filtering) | Crates.io |
walkdir | 2.4.0 | File system traversal | Crates.io |
chrono | 0.4.34 | Date and time handling | Crates.io |
tempfile | 3.18 | Temporary file operations | Crates.io |
fs_extra | 1.3.0 | File system extended operations | Crates.io |
dunce | 1.0.5 | File path normalization | Crates.io |
mockall | 0.13.1 | Unit test mocking tool | Crates.io |
privilege | 0.3.0 | Privilege management (for Windows privilege elevation) | Crates.io |
dirs | 6.0.0 | System directory path retrieval | Crates.io |
semver | 1.0 | Semantic version parsing | Crates.io |
reqwest | 0.12 | HTTP request client (with JSON support) | Crates.io |
rust-i18n | 3.1.3 | Internationalization and localization support | Crates.io |
runas | 1.2.0 | Windows command execution with elevated privileges (Windows-only) | Crates.io |
Notes:
-
Platform-Specific Dependencies:
runas
is Windows-only; other libraries are cross-platform (Linux/macOS/Windows).
-
Performance Optimization:
strip = true
: Removes debug symbols in release builds to reduce binary size.lto = "thin"
andopt-level = 3
: Enables Link-Time Optimization (LTO) and maximum optimization level.
-
Acknowledgements: Special thanks to these open-source projects for providing foundational support to
rdbkp2
!
Dependencies
~34–50MB
~1M SLoC