ansible-consul/files/cs-backup.sh

40 lines
750 B
Bash
Raw Normal View History

2022-03-12 14:44:06 +00:00
export PATH_SNAPSHOT=$1
export PATH_DIR="daily"
export PATH_BACKUP=$PATH_SNAPSHOT"/"$PATH_DIR
export TOKEN_AUTH_PROD=
export TOKEN_AUTH_STAGING=
export RETENTION=30
export ENV="0" # (0 = staging, 1 = production)
export SNAPSHOT_FILE=$(date +%Y-%m-%d)
select_env() {
if [ "$ENV" = "0" ]
then
export ENV_TOKEN="$TOKEN_AUTH_STAGING"
else
export ENV_TOKEN="$TOKEN_AUTH_PROD"
fi
}
create_snapshot_folder(){
mkdir -p $PATH_BACKUP
}
run_snapshot() {
select_env
/usr/bin/consul snapshot save -token=$ENV_TOKEN $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 $@