dbkp

package
v0.0.0-...-87a2a3b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package dbkp implements dotfiles backup and restore.

The dbkp package allows to easily backup and restore dotfiles to a folder. It will create a folder called dbkp containing all files and folders described in the Recipe struct. If encryption is used, instead of backing up to a folder, it will create a tarball with all files and encrypt the tarball using GCM-AES-256. Keys are derived from passwords using PBKDF2.

Index

Constants

This section is empty.

Variables

View Source
var Version string

Functions

func AskForPassword

func AskForPassword() ([]byte, error)

Asks for a password in the terminal, unix style.

func Backup

func Backup(path string, recipe Recipe, password []byte, pr chan<- ProgressReport) error

Executes the backup of the recipe into path/dbkp. If a password is given, make it an encrypted backup.

func Contains

func Contains(slice []string, str string) bool

Checks wether slice contains str

func Decrypt

func Decrypt(key []byte, salt string, ciphertext []byte) ([]byte, error)

Decrypts the ciphertext using the given key and salt (IV). Returns the raw data.

func DeriveKeyFromPassword

func DeriveKeyFromPassword(password []byte, salt string) ([]byte, string)

Uses PBKDF2 to derive a key from a password. Salt is an hexadecimal string. If salt is given and of correct size, use it; otherwise, generate a new one. Returns both the key and the salt, in order.

func Encrypt

func Encrypt(key []byte, data []byte) ([]byte, string, error)

Encrypts data using key and returns the ciphertext and IV. The IV is public information and can be stored unencrypted.

func Restore

func Restore(path string, recipe Recipe, password []byte, pr chan<- ProgressReport) error

func WriteExampleRecipe

func WriteExampleRecipe(path string) error

Write an recipe prefilled with some examples to path.

Types

type Command

type Command struct {
	Name    string // Uniquely represents this File and is also the name of the file/folder inside the backup folder.
	Backup  string // The backup command to execute.
	Restore string // The restore command to execute.
}

Represents a pair of Backup and Restore commands. Backup and Restore are strings because they will both be executed as `sh -c 'CMD'`. The output of Backup is saved to a file /path/to/backup/Name, which is read into the input of Restore when restoring.

type File

type File struct {
	Name     string      // Uniquely represents this File and is also the name of the file/folder inside the backup folder.
	Path     string      // The path to the file/folder to be backed up in the filesystem.
	Only     []string    // If Path is a folder, only backs up the items in Only, skipping all others.
	Exclude  []string    // If Path is a folder, excludes the items in Exclude from the backup.
	Symlinks [][2]string // After restoring, creates symlinks from /path/to/backup/Name/Symlinks[][0] into Symlinks[][1].
}

Represents a File or Folder backup.

type ProgressReport

type ProgressReport struct {
	Count uint64
	Total uint64
	Name  string
}

A function to be called informing that another file/folder is about to be backed up/restore.

type Recipe

type Recipe struct {
	EncryptionSalt [2]string // A pair of randon data. The first is for the key generator and the second for the encryption algorithm.
	Files          []File    // A list of File to backup/restore.
	Commands       []Command // A list of Command to backup/restore.
}

Identifies all elements of a backup, specifying what to backup/restore and whether the backup is encrypted. The pair of keys are regenerated every time a backup is done and the dbkp.toml file is created when the Tarball is written in the same folder as the Tarball itself.

func LoadRecipe

func LoadRecipe(path string) (Recipe, error)

Loads a recipe from a path. Just a convenience function to parse the TOML file.

func (Recipe) WriteRecipe

func (recipe Recipe) WriteRecipe(path string) error

Saves the recipe to a TOML file at path.

type Tarball

type Tarball struct {
	Buffer  bytes.Buffer
	Writter *tar.Writer
}

Represents a tarball file and holds its data. Should only be used to read or write, but not both at the same time. Since all operations is done in-memmory, this structure is not ideal for large files, but since configuration files are mostly only a few KB, at most a few MB, it is not a problem.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL