Created
June 25, 2021 07:16
-
-
Save frispete/1a975ff0e6bf425be4d2db8a9175504f to your computer and use it in GitHub Desktop.
script to save/restore ff sessions
This file contains hidden or 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
#!/bin/bash | |
#ssb=$(ls -d ~/.mozilla/firefox/*.default-esr68/sessionstore-backups) | |
ssb=$(find ~/.mozilla/firefox -regex '.*.default-[0-9]+')/sessionstore-backups | |
err() { | |
echo $* >&2 | |
exit 2 | |
} | |
usage() { | |
cat >&2 <<EOF | |
Store/list/restore firefox session backups | |
Usage: $0 [-hv] [-s ssb] [store]|restore ts|list | |
-h this message | |
-v verbose operation | |
-s ssb sessionstore-backups folder | |
Without arguments, default action is store. | |
Specify restore ts to restore the session backup, e.g.: | |
$0 restore 20190823-044501 | |
Given, recovery.jsonlz4.20190823-044501 exists, and is readable. | |
Usually, the sessionstore-backups folder is detected automatically. | |
EOF | |
echo 1 | |
} | |
while getopts hvs: par ; do | |
case $par in | |
h) usage;; | |
v) set -o xtrace;; | |
s) ssb="$OPTARG";; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
# check ssb validity | |
[ $(echo "$ssb" | wc -w) -eq 1 -a -d "$ssb" ] || err "$ssb: invalid sessionstore-backups folder" | |
action=store | |
[ -n "$1" ] && { action=$1; shift; } | |
case $action in | |
store) | |
ssr=$ssb/recovery.jsonlz4 | |
ts=$(date +%Y%m%d-%H%M%S) | |
[ -f "$ssr" ] && cp -a "$ssr" "$ssr.$ts" || err "$ssr not found" | |
;; | |
list) | |
pushd $ssb &>/dev/null | |
ls -ltr recovery.jsonlz4* | |
popd &>/dev/null | |
;; | |
restore) | |
ssr=$ssb/recovery.jsonlz4 | |
# remove recovery.jsonlz4. from ts argument | |
ts=${1##recovery.jsonlz4.} | |
[ -n "$ts" ] || err "no timestamp specified, check with list" | |
[ -f "$ssr~" ] && mv "$ssr~" "$ssr~~" | |
[ -f "$ssr" ] && mv "$ssr" "$ssr~" | |
[ -f "$ssr.$ts" ] && cp -a "$ssr.$ts" "$ssr" || err "$ssr.$ts not found" | |
;; | |
*) | |
err "unknown command: $action" | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment