Skip to content
/ bkp Public

Backup Your Packages Without Hassle

License

Notifications You must be signed in to change notification settings

LucaBarban/bkp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BacKup Packages

bkp is a simple python script that let’s you, backup all your installed packages by creating a shellscript, json or yaml file.

Requirements

Note
PyYaml is only needed if you plan on using the yaml output format.
  • python 3.X.X

  • PyYaml (optional)

Installation

Note
This script is meant to be modified and tweacked by the user. For this reason the only installation method is and will be manual.
mkdir -p ~/.local/bin
curl https://raw.githubusercontent.com/saccarosium/bkp/main/bkp -o ~/.local/bin/bkp
chmod +x ~/.local/bin/bkp

Why

I wanted to make my enviroment more easy to reproduce on other machine, mainly packages. So I’ve tryed a lot of the solutions I found online:

But none of them seemed to be a right fit to my very simple needs. I wanted something that: periodically backed up all my packages from all my available package managers and put it in something I could run everywhere without needing to install anything. Bkp does exactly this: it generetes a POSIX shellscript with all the packages installed by each individual package manager.

Note
You can use bkp also to automatically backup your backages to your Ansible playbook if you use the yaml output.

Example

I’ve installed the following packages with: pip, brew and gem

pip install ansible
brew install neovim gh fzf
gem install asciidoctor

The resulting script that bkp will generate will look something like this:

#!/bin/sh

pip install \
  ansible
brew install \
  neovim \
  git \ # (1)
  gh \
  fzf
gem install \
  asciidoctor
  1. Will include everything that will be listed in the Source List Command

How it works

In the script the is a global dictionary called SOURCES and in there you can find all the package managers:

SOURCES = {
    "brew": {
        "install": ["brew", "install"],
        "list": ["brew", "leaves", "--installed-on-request"],
        "singleCmd": True
    },
    "cask": {
        "install": ["brew", "install", "--cask"],
        "list": ["brew", "list", "--cask"],
        "singleCmd": True
    },
    "pipx": {
        "install": ["pipx", "install"],
        "list": ["pipx", "list", "--short"],
        "filter": lambda x: [v for i, v in enumerate(x) if i % 2 == 0],
        "singleCmd": False
    },
    "pip": {
        "install": ["pip", "install", "-u"],
        "list": ["pip", "list", "--not-required", "--format", "freeze"],
        "singleCmd": True
    },
    "gem": {
        "install": ["gem", "install"],
        "list": ["gem", "list", "--no-verbose", "--no-versions"],
        "singleCmd": True
    }
}

This dictionary follows the following schema:

"name": { # (1)
  "install": [], # (2)
  "list": [], # (3)
  "filter": "lambda", # (4)
  "singleCmd": "bool", # (5)
}
  1. name of used in the dictionary doesn’t really matter

  2. how you want that this package manager install software

  3. command used to gather a list of installed packages. Note that this will be turned into a list with the method .split().

  4. lambda function that is given the list of packages generated by the list cmd.

  5. does the package manager support passing multiple packages in a single command call

Usage

bkp --help

About

Backup Your Packages Without Hassle

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages