Skip to content

Commit

Permalink
limit number of crash recovery snapshots, graysky2#191
Browse files Browse the repository at this point in the history
  • Loading branch information
graysky2 committed Nov 25, 2016
1 parent 8bafa6e commit f4adfd0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 6.29
VERSION = 6.30
PN = profile-sync-daemon

PREFIX ?= /usr
Expand Down
32 changes: 30 additions & 2 deletions common/profile-sync-daemon.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ if [[ -f "$PID_FILE" ]]; then
fi
fi

# define default number of crash-recovery snapshots to save if the user did not
# and check that it is an integer if user did define it
if [[ -z "$BACKUP_LIMIT" ]]; then
BACKUP_LIMIT=5
else
if [[ "$BACKUP_LIMIT" =~ ^[0-9]+$ ]]; then
# correctly setup
/bin/true
else
echo -e " ${RED}ERROR:${NRM}${BLD} Bad value for BACKUP_LIMIT detected!${NRM}"
exit 1
fi
fi

# BROWSERS defined as string var so redefine it as an array
if [[ -z "$BROWSERS" ]]; then
BROWSERS=( $(find "$SHAREDIR/browsers" -type f -printf "%f\n") )
Expand Down Expand Up @@ -296,7 +310,7 @@ cleanup() {
load_env_for "$browser"
for item in "${DIRArr[@]}"; do
DIR="$item"
CRASHArr=( $(find "${DIR%/*}" -type d -name '*crashrecovery*') )
CRASHArr=( $(find "${DIR%/*}" -type d -name '*crashrecovery*'|sort -r) )
if [[ ${#CRASHArr[@]} -gt 0 ]]; then
echo -e "${BLD}Deleting ${#CRASHArr[@]} crashrecovery dir(s) for profile ${BLU}$DIR${NRM}"
for backup in "${CRASHArr[@]}"; do
Expand Down Expand Up @@ -509,6 +523,19 @@ for browser in "${BROWSERS[@]}"; do
done
}

enforce() {
local browser
for browser in "${BROWSERS[@]}"; do
CRASHArr=( $(find "${DIR%/*}" -type d -name '*crashrecovery*'|sort -r) )
if [[ ${#CRASHArr[@]} -gt $BACKUP_LIMIT ]]; then
for remove in "${CRASHArr[@]:$BACKUP_LIMIT}"; do
rm -rf "$remove"
done
fi
unset CRASHArr
done
}

do_unsync() {
rm -f "$PID_FILE" "$PSDCONFDIR/.psd.conf"

Expand Down Expand Up @@ -576,7 +603,7 @@ parse() {
fi
UPPER="$VOLATILE/$user-$browser${suffix}-rw"
if [[ -d "$DIR" ]]; then
CRASHArr=( $(find "${DIR%/*}" -type d -name '*crashrecovery*') )
CRASHArr=( $(find "${DIR%/*}" -type d -name '*crashrecovery*'|sort -r) )
# get permissions on profile dir and be smart about it since symlinks are all 777
[[ -f $PID_FILE ]] && TRUEP=$(stat -c %a "$BACKUP") || TRUEP=$(stat -c %a "$DIR")
# since $XDG_RUNTIME_DIR is 700 by default so pass on by
Expand Down Expand Up @@ -652,6 +679,7 @@ case "$1" in
running_check
ungraceful_state_check
do_sync
enforce
fi
;;
unsync)
Expand Down
6 changes: 6 additions & 0 deletions common/psd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@
# dead, etc. Some users keep very diligent backups and don't care to have this
# feature enabled.
#USE_BACKUPS="yes"

# Uncomment and set to an integer that is the maximum number of crash recovery
# snapshots to keep (the oldest ones are delete first).
#
# The default is to save the most recent 5 crash recovery snapshots.
#BACKUP_LIMIT=5
6 changes: 4 additions & 2 deletions doc/psd.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.\" Text automatically generated by txt2man
.TH profile-sync-daemon 1 "01 October 2016" "" ""
.TH profile-sync-daemon 1 "25 November 2016" "" ""
.SH NAME
\fBprofile-sync-daemon \fP- Symlinks and syncs browser profiles to RAM (tmpfs) thus reducing HDD/SSD calls and speeding-up browsers.
\fB
.SH DESCRIPTION
Profile-sync-daemon (psd) is a tiny pseudo-daemon designed to manage browser profile/profiles in tmpfs and to periodically sync back to the physical disc (HDD/SSD). This is accomplished by an innovative use of rsync to maintain synchronization between a tmpfs copy and media-bound backup of the browser profile/profiles. Additionally, psd features several crash recovery features.
Profile-sync-daemon (psd) is a tiny pseudo-daemon designed to manage browser profile/profiles in tmpfs and to periodically sync back to the physical disc (HDD/SSD). This is accomplished by an innovative use of rsync to maintain synchronization between a tmpfs copy and media-bound backup of the browser profile/profiles. Additionally, psd features several crash-recovery features.
.PP
Design goals of psd:
.RS
Expand All @@ -30,6 +30,8 @@ Optionally enable the use of overlayfs to improve sync speed and to use a smalle
Optionally define which browsers are to be managed in the BROWSERS array. If none are defined, the default is all detected browsers.
.IP \(bu 3
Optionally disable the use of crash-recovery snapshots (not recommended). Do this in the USE_BACKUPS variable.
.IP \(bu 3
Optionally define the number of crash-recovery snapshots to keep. Do this in the BACKUP_LIMIT variable.
.SH RUNNING PSD
.SS PREVIEW MODE
The preview option can be called to show users exactly what psd will do/is doing based on the entries in the config file. It will also provide useful information such as profile size, paths, and if any recovery snapshots have been created.
Expand Down

0 comments on commit f4adfd0

Please sign in to comment.