Skip to content

sysadmin.vault #

Vault

Methods to keep history of folders, can be used as a backup solution.

the result will be .vault folders in each directory which have the history of files as well as version nr's

./.vault
./.vault/newfile1.1
./.vault/meta
./markdownparser
./newfile1
./test_parent
./test_parent/.test_ignore
./test_parent/.vault
./test_parent/.vault/readme.1.md
./test_parent/.vault/meta
./test_parent/readme.md

a metadata file looks like

a73f7818de83bcc1dc4fe89190b2d3054bd37c10bb1ed055693292f2da50cba3|1662454965|1|newfile1
b7129644df8d551f6b3f2905e5b44795087f4da77a62b1ad663f5b107ca9dac2|1662454965|1|readme.md
cc1dc4fe89190b2d3c4fe89190b2d3054bd37c10bb1ed055693290b2d3054bd3|1662454980|2|newfile1

the nr's will go up if new version, newfile got 2 versions here

restore

not implemented yet

fn do #

fn do(path string) !Vault

scan dir & subdirs, create a vault for it

fn get #

fn get(path string) !Vault

get the vault object from existing dir

fn scan #

fn scan(name string, mut path pathlib.Path) !Vault

scan dir & subdirs, create a vault for it will not do the shelving let, will just create or load the vault attached to it

fn vaults_delete #

fn vaults_delete(mut path pathlib.Path) !

walk over folders, find the vaults and delete them

struct Item #

struct Item {
mut:
	shelve &Shelve @[str: skip]
pub:
	sha256 string
	time   time.Time
	nr     u16
	name   string
}

fn (Item) meta #

fn (i Item) meta() string

save the metadata for the backups

fn (Item) sha256 #

fn (i Item) sha256() !string

save the metadata for the backups

fn (Item) name_nr #

fn (i Item) name_nr() string

get the name of the item in the shelve if its the first one then its the original name

struct Shelve #

struct Shelve {
pub mut:
	items   []Item
	path    pathlib.Path // path of the dir which is represented by the shelve
	changed bool
}

represents one directory in which backup was done is like a shelve in a vault

fn (Shelve) save #

fn (mut shelve Shelve) save() !

save the metadata for the backups

fn (Shelve) load #

fn (mut shelve Shelve) load() !

load the shelve, if its not there yet, then will return empty

fn (Shelve) shelve #

fn (mut shelve Shelve) shelve() !

walk over the directory which is represented by the shelve, walk over it and find new elements

fn (Shelve) latest_nr #

fn (mut shelve Shelve) latest_nr(name string) int

find the latest item for specific name, if it does not exist will create

fn (Shelve) exists #

fn (mut shelve Shelve) exists(name string) bool

check if we can find the name on the shelve

fn (Shelve) latest #

fn (mut shelve Shelve) latest(name string) Item

find the latest item for specific name, if it does not exist will create

fn (Shelve) add #

fn (mut shelve Shelve) add(mut path pathlib.Path) !Item

add a file to the shelve

fn (Shelve) delete #

fn (mut shelve Shelve) delete() !

delete the shelve info

fn (Shelve) superlist #

fn (mut shelve Shelve) superlist() string

walk over the vault and re-shelve all dir's as owned by the vault

struct Vault #

struct Vault {
pub mut:
	name    string
	shelves []Shelve
	changed bool // if true it means that a change happened somewhere in the vault
}

fn (Vault) shelve_get #

fn (mut vault Vault) shelve_get(mut path pathlib.Path) !Shelve

fn (Vault) shelve #

fn (mut vault Vault) shelve() !

walk over the vault and re-shelve all dir's as owned by the vault

fn (Vault) delete #

fn (mut vault Vault) delete() !

delete the vault remove all dirs

fn (Vault) superlist #

fn (mut vault Vault) superlist() string

walk over the vault and re-shelve all dir's as owned by the vault

fn (Vault) hash #

fn (mut vault Vault) hash() string

walk over the vault and re-shelve all dir's as owned by the vault

fn (Vault) restore #

fn (mut vault Vault) restore(unixtime int) !

restore to the unixtime state only implemented to go to 0, which is the first state

Todo: implement restore on other times