Nutshell

Thoughts come and go, words stay eternal

17 Dec 2019

Abstract

  1. Always backup configuration or data before update it (or use git like tools manage data version)
  2. Seperate operations into five steps:
    1. backup
    2. pre-test
    3. update
    4. post-test
    5. rollback or finished

Introduction

Basic

Rules:

  1. Every Operation must has RollBack Operation
  2. All ops done success or no ops done

Transaction Ops Rule:

  1. Stages
    1. Backup Stage
      • backup current system state
      • GoTo Next if Success
      • Exit if it fails
    2. PreTest Stage
      • in order to generate test rule
      • make sure system working before apply operation
      • GoTo Next if Success
      • Exit if it fails
    3. Operate Stage
      • do the operation that we want to do
      • GoTo Next if Success
      • GoTo RollBack Stage if it fails
    4. PostTest Stage
      • apply custom-built test rule
      • apply test rule generate in PreTest Stage
      • GoTo RollBack Stage if it fails
    5. RollBack Stage
      • only exec while Failed PostTest Stage
      • apply Backup Stage to rollback system
  2. 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