Separate config file, rollback cleanup systemd-unit #15

Merged
jarno merged 4 commits from config-file into master 2020-08-07 11:32:13 +03:00
2 changed files with 45 additions and 2 deletions
Showing only changes of commit 3585d5720c - Show all commits

37
snapsh
View File

@ -226,6 +226,34 @@ rollback() {
post-rollback() {
## This function is meant to be executed by the included systemd unit on every boot
## Outputs to systemd-journal, use journalctl -t snapsh to check output
EXIT_CODE=0
shopt -s nullglob
echo "Checking for leftover subvolumes..." | systemd-cat -t snapsh
BACKUPS=("${TOPLEVEL}/*.backup/")
if [[ -n "$BACKUPS" ]]; then
for backup in ${TOPLEVEL}/*.backup/; do
echo "${backup} found" | systemd-cat -t snapsh
echo "Deleting ${backup}..." | systemd-cat -t snapsh
${BTRFS_EXECUTABLE} subvolume delete ${backup} > /dev/null
let EXIT_CODE=${EXIT_CODE}+$?
done
exit ${EXIT_CODE}
else
echo "No leftovers found." | systemd-cat -t snapsh
exit 0
fi
}
# Check for root permissions # Check for root permissions
root_check() { root_check() {
if [[ "$UID" -ne 0 ]]; then if [[ "$UID" -ne 0 ]]; then
@ -244,7 +272,7 @@ fi
# Options parsing: # Options parsing:
OPTIONS=$(getopt -a -n snapsh -o hs:d:lr:t: --long help,snapshot:,description:,list,remove:,rollback:,type: -- "$@") OPTIONS=$(getopt -a -n snapsh -o hs:d:lr:t: --long help,snapshot:,description:,list,remove:,rollback:,type:,post-rollback -- "$@")
# Invalid options (getopt returns nonzero) # Invalid options (getopt returns nonzero)
if [[ "$?" -ne 0 ]]; then if [[ "$?" -ne 0 ]]; then
@ -292,6 +320,11 @@ while true; do
rollback rollback
shift 2 shift 2
;; ;;
--post-rollback)
post-rollback
shift
;;
-t | --type) -t | --type)
case "$2" in case "$2" in
@ -322,4 +355,4 @@ if [[ -n "${SNAPSHOT}" ]]; then
snapshot snapshot
elif [[ -n "${LIST}" ]]; then elif [[ -n "${LIST}" ]]; then
list list
fi fi

View File

@ -0,0 +1,10 @@
[Unit]
Description=Remove leftover *.backup subvolumes
[Service]
Type=oneshot
ExecStart=/usr/sbin/snapsh --post-rollback
RemainAfterExit=yes
[Install]
WantedBy=default.target