Skip to content
/ bk Public

POSIX script to save/restore/diff dot-files with a git versionend directory

License

Notifications You must be signed in to change notification settings

invarianz/bk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

(B)ac(k)up → bk

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

Installation

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.

Options

  • -i: Initalize the directory structure in $HOME by creating all necessary parent directories for files stored in $BK. Skips existing directories.
  • -d: Diff each file in $BK against the corresponding file in $HOME. Uses cmp and diff. Prints
    • == for identical files (in green)
    • != for differing files (in red)
  • -s: Save all changed files from $HOME into $BK. Overwrites files in $BK as needed! Prints
    • == for identical files (in green)
    • -> when saving from $HOME to $BK (in red)
  • -r: Restore all changed files from $BK (e.g. after a git pull in $BK) into $HOME. Overwrites files in $HOME as needed. Prints
    • == for identical files (in green)
    • <- when restoring from $BK to $HOME (in red)

If no option is provided, bk defaults to -d (diff)

Example Workflow

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.

Notes

  • .git directories inside $BK are ignored.
  • Output uses ANSI colors for visibility.
  • All comparisons are done using cmp, followed by a diff if files differ.

About

POSIX script to save/restore/diff dot-files with a git versionend directory

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages