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 ¶
- Variables
- func AskForPassword() ([]byte, error)
- func Backup(path string, recipe Recipe, password []byte, pr chan<- ProgressReport) error
- func Contains(slice []string, str string) bool
- func Decrypt(key []byte, salt string, ciphertext []byte) ([]byte, error)
- func DeriveKeyFromPassword(password []byte, salt string) ([]byte, string)
- func Encrypt(key []byte, data []byte) ([]byte, string, error)
- func Restore(path string, recipe Recipe, password []byte, pr chan<- ProgressReport) error
- func WriteExampleRecipe(path string) error
- type Command
- type File
- type ProgressReport
- type Recipe
- type Tarball
Constants ¶
This section is empty.
Variables ¶
var Version string
Functions ¶
func AskForPassword ¶
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 DeriveKeyFromPassword ¶
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 ¶
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 ¶
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 ¶
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 ¶
Loads a recipe from a path. Just a convenience function to parse the TOML file.
func (Recipe) WriteRecipe ¶
Saves the recipe to a TOML file at path.
type Tarball ¶
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.