32 lines
737 B
Bash
Executable File
32 lines
737 B
Bash
Executable File
#!/bin/sh
|
|
export PATH_SNAPSHOT="/backup"
|
|
export PATH_DIR="daily"
|
|
export PATH_BACKUP=$PATH_SNAPSHOT"/"$PATH_DIR
|
|
export VAULT_ADDR="http://active.vault.service.consul:8200"
|
|
export RETENTION=30
|
|
export ENV="0" # (0 = staging, 1 = production)
|
|
export SNAPSHOT_FILE=$(date +%Y-%m-%d)
|
|
|
|
|
|
create_snapshot_folder(){
|
|
mkdir -p $PATH_BACKUP
|
|
}
|
|
|
|
run_snapshot() {
|
|
export VAULT_TOKEN=$(/bin/vault write -field=token auth/approle/login role_id=$VAULT_APPROLEID secret_id=$VAULT_SECRETID)
|
|
/bin/vault operator raft snapshot save $PATH_BACKUP/$SNAPSHOT_FILE.snap
|
|
}
|
|
|
|
retention() {
|
|
find $PATH_BACKUP -name "*.snap" -mtime +${RETENTION} -print -exec rm {} \;
|
|
}
|
|
|
|
main() {
|
|
create_snapshot_folder
|
|
run_snapshot
|
|
retention
|
|
}
|
|
|
|
### START HERE ###
|
|
main $@
|