bk is a minimal, fully POSIX-compliant shell script for synchronizing files
between a designated backup directory and your $HOME directory.
- Goals: Simplicity, clarity, POSIX compliance
- Non-Goals: Multi-host backup, version control
To use bk, you must define the BK environment variable to point to your
backup directory. This directory must contain a copy of the files you want to
manage (e.g., dotfiles, config files).
Example:
export BK="$HOME/.bk"You should also place the bk script somewhere in your executable $PATH, such
as /usr/local/bin or ~/.local/bin.
-i: Initalize the directory structure in$HOMEby creating all necessary parent directories for files stored in$BK. Skips existing directories.-d: Diff each file in$BKagainst the corresponding file in$HOME. Usescmpanddiff. Prints==for identical files (in green)!=for differing files (in red)
-s: Save all changed files from$HOMEinto$BK. Overwrites files in$BKas needed! Prints==for identical files (in green)->when saving from$HOMEto$BK(in red)
-r: Restore all changed files from$BK(e.g. after a git pull in$BK) into$HOME. Overwrites files in$HOMEas needed. Prints==for identical files (in green)<-when restoring from$BKto$HOME(in red)
If no option is provided, bk defaults to -d (diff)
export BK="$HOME/.bk"
mkdir -p "$BK/mytool"
cp ~/.bashrc "$BK/.bashrc"
cp ~/.config/mytool/config "$BK/.config/mytool/config"
# Save updated files (i.e. if you change ~/.bashrc)
bk -s
# Review differences
bk
# Restore files from $BK
bk -r
This tool makes most sense when paired with git, i.e., your $BK directory
should be under version control. If you push a change on a different system and
pull it, you can easily restore the files to your $HOME dir. Also the other
way round: if you change something in your $HOME dir, you can easily diff with
the old config in $BK, save to $BK and push.
.gitdirectories inside$BKare ignored.- Output uses ANSI colors for visibility.
- All comparisons are done using
cmp, followed by adiffif files differ.