backive

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: BSD-3-Clause Imports: 13 Imported by: 0

README

backive

The name comes from the combination of backup and archive - silly, I know.

Purpose

I've a long-term backup strategy where I put some labeled hard-disk in a SATA docking station and run a backup routine. When done, this hard-disk goes back into some shelf in my attic or basement. When the time is come again to update the long-term backup the same procedure starts again.

So now there are my backup routines, which are manually currently - and that sucks.

So what this tool or service should do is the following:

  • I am able to configure based on UUIDs of the partitions which devices are allowed for backup
  • I can specify as much backup items as I want, which should include:
    • Backup local and remote data (Linux machine and SSH required)
    • Use the best tool available for the task (rsync, duplicity, whatever)
    • Even be able to "backup" without a target device (choose another path on the system)
    • (optional) Be able to run pre-backup commands (for databases maybe), remote too
  • The service has to be able to automatically detect the presence of a hard-disk, mounting it, running the backup routine and unmounting
  • Good logging about the process

What I currently see as optional:

  • Notification about the finished process

Technical goals

  • systemd service
  • udev rules for notifications about new drives
  • Golang implementation

Current state

Working daemon and udev binary. Ready for first basic usage and testing in "production".

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDirectoryIfNotExists

func CreateDirectoryIfNotExists(dir string) error

CreateDirectoryIfNotExists Checks for a directory string and creates the directory if it does not exist, must be a absolute path.

func Init

func Init(cfg Configuration, db Database)

Init initializes backive with the two basic data structures required, the config, and the database

Types

type Backup

type Backup struct {
	Name         string      `mapstructure:",omitempty"`
	TargetDevice string      `mapstructure:"targetDevice"`
	TargetPath   string      `mapstructure:"targetPath"`
	SourcePath   string      `mapstructure:"sourcePath"`
	ScriptPath   interface{} `mapstructure:"scriptPath"`
	Frequency    int         `mapstructure:"frequency"`
	ExeUser      string      `mapstructure:"user,omitempty"`
	Label        string      `mapstructure:"label,omitempty"`
	// contains filtered or unexported fields
}

Backup contains all necessary information for executing a configured backup.

func (*Backup) CanRun

func (b *Backup) CanRun() error

CanRun Checks the configuration items required and checks the frequency setting with the run database if a Backup should run.

func (*Backup) PrepareRun

func (b *Backup) PrepareRun() error

PrepareRun prepares a run for a backup, creates a logger for the execution of the backup script and gives the rights of the directory recursively to the user specified.

func (*Backup) Run

func (b *Backup) Run() error

Run runs the backup script with appropriate rights.

func (*Backup) ShouldRun

func (b *Backup) ShouldRun() bool

ShouldRun Takes a backup key and returns a bool if a backup should run now.

type Backups

type Backups map[string]*Backup

Backups is nothing else than a name to Backup type mapping

func (*Backups) FindBackupsForDevice

func (bs *Backups) FindBackupsForDevice(d Device) ([]*Backup, bool)

FindBackupsForDevice only finds the first backup which is configured for a given device.

type Configuration

type Configuration struct {
	Settings Settings `mapstructure:"settings"`
	Devices  Devices  `mapstructure:"devices"`
	Backups  Backups  `mapstructure:"backups"`
	Vconfig  *viper.Viper
}

Configuration struct holding the settings and config items of devices and backups

func (*Configuration) CreateViper

func (c *Configuration) CreateViper()

CreateViper creates a viper instance for usage later

func (*Configuration) Load

func (c *Configuration) Load()

Load loads the configuration from the disk

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database is a simple string to string mapping, where arbitrary strings can be stored and safed to disk or loaded

func (*Database) Load

func (d *Database) Load()

Load loads the database

func (*Database) Save

func (d *Database) Save()

Save saves the database

type Device

type Device struct {
	Name      string `mapstructure:",omitempty"`
	UUID      string `mapstructure:"uuid"`
	OwnerUser string `mapstructure:"owner,omitempty"`
	// contains filtered or unexported fields
}

Device represents a device, with a name easy to remember and the UUID to identify it, optionally an owner.

func (*Device) IsMounted

func (d *Device) IsMounted() bool

IsMounted returns the mount state of the device

func (*Device) Mount

func (d *Device) Mount() error

Mount will mount a device

func (*Device) Unmount

func (d *Device) Unmount() error

Unmount will unmount a device

type Devices

type Devices map[string]*Device

Devices is nothing else than a name to Device type mapping

type EventHandler

type EventHandler struct {
	// contains filtered or unexported fields
}

EventHandler holds the necessary elements to get an eventhandler setup and working.

func (*EventHandler) Init

func (eh *EventHandler) Init(socketPath string) error

Init initializes the unix socket.

func (*EventHandler) Listen

func (eh *EventHandler) Listen()

Listen starts the event loop.

func (*EventHandler) RegisterCallback

func (eh *EventHandler) RegisterCallback(cb func(map[string]string))

RegisterCallback adds a function to the list of callback functions for processing of events.

type Runs

type Runs struct {
	// contains filtered or unexported fields
}

Runs contains the Data for the scheduler: mapping from backups to a list of timestamps of the last 10 backups

func (*Runs) LastRun

func (r *Runs) LastRun(b *Backup) (time.Time, error)

LastRun returns the time.Time of the last run of the backup given.

func (*Runs) Load

func (r *Runs) Load(db Database)

Load loads the data from the json database

func (*Runs) RegisterRun

func (r *Runs) RegisterRun(b *Backup)

RegisterRun saves a date of a backup run into the internal storage

func (*Runs) Save

func (r *Runs) Save(db Database)

Save saves the data into the json database

type Settings

type Settings struct {
	SystemMountPoint   string `mapstructure:"systemMountPoint"`
	UserMountPoint     string `mapstructure:"userMountPoint"`
	UnixSocketLocation string `mapstructure:"unixSocketLocation"`
	LogLocation        string `mapstructure:"logLocation"`
	DbLocation         string `mapstructure:"dbLocation"`
}

Settings struct holds the global configuration items

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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