Skip to content

Instantly share code, notes, and snippets.

@mubeeniqbal
Created December 1, 2014 16:28
Show Gist options
  • Save mubeeniqbal/a063912439b0e94c245b to your computer and use it in GitHub Desktop.
Save mubeeniqbal/a063912439b0e94c245b to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
#
# Written by: crossroads1112
# Purpose: This script is complimentary to the snp script. It makes the process rolling back upgrades and daily snapshots easier
#
#
#
################################
log_path="/var/local/log/rollback"
date=$(date "+%Y-%m-%d-%H%M%S")
log_file="${log_path}/rollback_${date}.log"
PS3="Choice: "
if (( EUID != 0 )); then
echo "This script must be run as root" 1>&2
exit 1
fi
if [ ! -d "$log_path" ]; then #If log directory does not exist, create it
mkdir -p $log_path
fi
exec > >(tee -a "$log_file") #Log stdout and stderr to a file while still displaying it in term
exec 2> >(tee -a "$log_file" >&2)
clear
menu(){
echo "What do you want to rollback?"
select input in 'Timeline snapshot' 'Upgrade'; do
case $input in
'Upgrade')
clear
echo 'Undoing most recent upgrade'
pre=$(sudo snapper list --type pre-post | tail -n -1 | awk -F\| '{print $1}' | tr -d ' ') #Get number of most recent pre snapshot
snapper -v undochange $pre..$((pre+1)) #Undo the changes from $pre and the one right after it
;;
'Timeline snapshot')
clear
snapper list --type single | awk -F\| '{print $1"|" $2}'| sed '1,3d' #Show a list of all single snapshots
echo -en "\nNumber of the snapshot you like to return to: "
read past
snapper -v undochange $past..0 #Undo change from sekected snapshot to now
;;
esac
read -p "All done, press [ENTER] to go back to the menu or Ctrl-C to exit"
clear
menu
done
}
menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment