[SRE] Transaction Ops
Abstract
- Always backup configuration or data before update it (or use git like tools manage data version)
- Seperate operations into five steps:
backup
pre-test
update
post-test
rollback
orfinished
Introduction
Basic
Rules:
- Every Operation must has RollBack Operation
- All ops done success or no ops done
Transaction Ops Rule:
- Stages
- Backup Stage
- backup current system state
- GoTo Next if Success
- Exit if it fails
- PreTest Stage
- in order to generate test rule
- make sure system working before apply operation
- GoTo Next if Success
- Exit if it fails
- Operate Stage
- do the operation that we want to do
- GoTo Next if Success
- GoTo RollBack Stage if it fails
- PostTest Stage
- apply custom-built test rule
- apply test rule generate in PreTest Stage
- GoTo RollBack Stage if it fails
- RollBack Stage
- only exec while Failed PostTest Stage
- apply Backup Stage to rollback system
- Backup Stage
- Use Transaction Ops Framework
Example - Update Network Route
#!/bin/bash
set -u
# notify
notify(){
# do notify
}
# 1. backup network route
backup_route(){
# do something
}
# 2. generate test-case
generate_testcase(){
# do something
# nameserver in /etc/hosts
# other connection via "contrack" or "ss" command
}
# 3. update network route
update_route(){
# do something
}
# 4. apply test-case
apply_testcase(){
# do something
}
# 5. rollback network route
rollback_route(){
# do something
}
# main
main(){
backup_route \
&& generate_testcase \
&& update_route \
&& (apply_testcase || rollback_route)
if [ $? -ne 0 ]
then
notify
fi
}
main