Last active
April 15, 2025 04:11
-
-
Save cmlsharp/4f8eeeffdb3e87526b23 to your computer and use it in GitHub Desktop.
Script that makes it easy to rollback snapshots with snapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
log_path="/var/local/log/rollback" | |
date=$(date "+%Y-%m-%d-%H%M%S") | |
log_file="${log_path}/rollback_${date}.log" | |
#If log directory doesnt exist, make it | |
if [ ! -d "$log_path" ]; then | |
mkdir $log_path | |
fi | |
# Log stdout and stderr. | |
exec > >(tee -a "$log_file") | |
exec 2> >(tee -a "$log_file" >&2) | |
clear | |
echo 'Do you want to rollback a [d]aily snapshot or an [u]pgrade?' | |
read input | |
if [ $input == "u" ]; then | |
clear | |
echo 'Undoing most recent upgrade' | |
pre=$(sudo snapper list --type pre-post | tail -n -1 | awk -F\| '{print $1}' | tr -d ' ') #Grabs the most recent pre snapshot number | |
snapper -v undochange $pre..$((pre+1)) #Undoes the change between the most recent pre and the snapshot right after (the most recent post) | |
elif [ $input == "d" ]; then | |
clear | |
snapper list --type single | awk -F\| '{print $1"|" $2}'| sed '1,3d' | |
echo -e "\n What is the number of the snapshot you like to return to?" | |
read past | |
snapper -v undochange $past..0 #Undoes the changes between the selected snapshot number and your filesystem as it is now | |
else | |
echo "$input is not an acceptable response" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment