dump-session: too many error messages

Please reproduce your error on a second machine before posting, and check the error by running without saved changes or extra modules (See FAQ No. 13, "How to report a bug"). For unstable Porteus versions (alpha, beta, rc) please use the relevant thread in our "Development" section.
User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 4253
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
Location: australia
Contact:

dump-session: too many error messages

Post#46 by ncmprhnsbl » 17 Jul 2024, 09:12

another updated version:
zz-changes-exit-test.xzm
timeout/skip action disabled for in-session commit (in line with the original dump-session)
some excess tests removed
(on shutdown/reboot) in the case of space warning, instead of adding sleep 5 to the 3 of timeout, the total timeout is set to 5.
when no space warning the default 3 timeout is used.
space amounts in human readable (Kb/Mb/Gb)
added redirect 1>/dev/tty1 after command in rc.6, this seems to work for if you use poweroff or reboot from a terminal in X session. (and isn't a problem with corrected elogind exiting)
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

rych
Warlord
Warlord
Posts: 766
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

dump-session: too many error messages

Post#47 by rych » 17 Jul 2024, 12:17

ncmprhnsbl wrote:
17 Jul 2024, 00:50
use `loginctl poweroff`
Yes, that fixed it: now the rc.6 output is on vt1.
I've also added in .bashrc:

Code: Select all

alias reboot="loginctl reboot"
alias poweroff="loginctl poweroff"
ncmprhnsbl wrote:
15 Jul 2024, 00:18
sleep 3 to the beginning of rc.6 (it may need longer
I've actually commented it out, and it still runs and displays colored messages and without delay -- perhaps that sleep isn't needed anymore (now that I've learnt to use the `loginctl poweroff` :)

rych
Warlord
Warlord
Posts: 766
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

dump-session: too many error messages

Post#48 by rych » 20 Jul 2024, 10:50

ncmprhnsbl wrote:
17 Jul 2024, 00:50
the decision to skip/not skip is(or should be) made well before shutdown, with the user ready with their finger on either enter/space(to skip the countdown) or any other key(to skip the save(and the countdown))
OK. At the moment, one would need to press the "any other key" twice, because initrd/cleanup would still try to run its own changes-commit block because the /mnt/live/tmp/changes-exit wouldn't have been removed. But I understand in the future initrd that block will be commented out completely.

Anyway, here's my own `my-changes-commit` dangerously stripped of all the checks:

Code: Select all

#!/bin/bash
# Commits live session (RAM) to the active changes folder
# Script takes action only when 'changes=EXIT' cheatcode is used.
# Edit /etc/changes-exit.conf to in/exclude files and folders.
# Upstream: ncmprhnsbl's changes-commit
# Customized by rych

# Check if 'changes=EXIT' cheatcode is active
test -f /mnt/live/tmp/changes-exit || { echo "'changes=EXIT:' cheatcode is not active - exiting..."; exit; }

## Variables:
DEST="$(cat /mnt/live/tmp/changes-exit)"; NAME="$(basename $DEST)"
MNAME=/mnt/live/memory/images/changes   ; INAME=/mnt/live/memory/images
CHNEXIT_CONF=/etc/changes-exit.conf     ; EXCL=/tmp/save.excl.tmp
SFILES=/tmp/save.sfiles.tmp             ; UPDATE=/tmp/save.update.tmp

# Fix folder names and make `egrep' interpret wildcards
fixdir() { sed -e 's_\._\\._g' -e 's_?_._g' -e 's_*_.*_g' -e 's@..@^@'; }

# Fix whiteout names so `egrep' doesn't interpret special characters as regex
fixwh() { sed -e 's_\._\\._g' -e 's_?_\\?_g' -e 's_+_\\+_g' -e 's_*_\\*_g' -e 's_\$_\\$_g' -e 's_\[_\\[_g' -e 's_(_\\(_g'  -e 's_\&_\\&_g' -e 's@^@^@'; }

# Folders to save: argument for `find' & check that they exist.
FOLDERS="$(for x in $(grep ^/ $CHNEXIT_CONF | sed s/.//); do test -e /mnt/live/memory/changes/$x && echo $x; done)"

# Folders to exclude: argument for `egrep'
grep ^!/ $CHNEXIT_CONF | fixdir > $EXCL

## Save session:
echo "Syncing what's left in buffers"
sync

# Remount aufs with 'udba=notify' flag: 
mount -o remount,udba=notify / 
echo "saving changes to $DEST - this may take a while..."
cd /mnt/live/memory/changes

# Handle filenames with spaces.
IFS="
"

# Remove deleted files and non matching whiteouts
for y in $(find $FOLDERS -name ".wh.*"); do
  f="$(echo $y | sed 's@\.wh\.@@g')"
  test -e "$MNAME/$f" && rm -rf "$MNAME/$f";
  test -e "$INAME/"*"/$f" || { echo "$y" | fixwh >> $EXCL; test -e "$MNAME/$y" && rm -f "$MNAME/$y"; }
done

# Copy new and modified files -- skip excluded whiteouts and folders
{ test -s "$EXCL" && find $FOLDERS -not -type d | egrep -vf $EXCL || find $FOLDERS -not -type d; } > $SFILES
cp -uafv --parents $(cat $SFILES) $MNAME > $UPDATE

# Remove conflicting whiteouts
for y in $(find $MNAME -name ".wh.*"); do
	f="$(echo $y | sed -e 's^$MNAME^^g' -e 's^\.wh\.^^g')";
	test -e "$f" && rm "$y";
done

# Reset IFS to default
unset IFS
# Remount aufs with 'udba=none' flag:
mount -o remount,udba=none /
echo "Session saved"
When I run it at the end of my session, I also do this:

Code: Select all

mv -f /mnt/live/tmp/changes-exit /mnt/live/tmp/changes-exitDONE
Thanks for your help! We can consider this SOLVED.

User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 4253
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
Location: australia
Contact:

dump-session: too many error messages

Post#49 by ncmprhnsbl » 21 Jul 2024, 02:12

rych wrote:
17 Jul 2024, 12:17
I've actually commented it out, and it still runs and displays colored messages and without delay -- perhaps that sleep isn't needed anymore (now that I've learnt to use the `loginctl poweroff`
interesting, i havn't witnessed this myself.. could be desktop dependent, ie. some desktops might take longer for elogind to deal with, stopping processes and such..
note the other thing i added to the last update: an stdout redirect to tty1in rc.6 for changes-commit:

Code: Select all

# Run changes-commit for changes=EXIT:
[ -f /mnt/live/tmp/changes-exit ] && /opt/porteus-scripts/changes-commit 6 1>/dev/tty1
which negates the need for elogind's proper exit or any sleep for that (although properly exiting elogind is probably sound practice)
rych wrote:
20 Jul 2024, 10:50
OK. At the moment, one would need to press the "any other key" twice, because initrd/cleanup would still try to run its own changes-commit block because the /mnt/live/tmp/changes-exit wouldn't have been removed. But I understand in the future initrd that block will be commented out completely.
ah, good point (didn't notice in my basic tests by not bothering to skip :p)
easily fixed by moving the rm part out of the conditional. and as you say, this is only a temporary measure for backward compatibilty with unmodified initrds.
rych wrote:
20 Jul 2024, 10:50
Anyway, here's my own `my-changes-commit` dangerously stripped of all the checks:
which highlights the benefit of moving this action out of initrd, making it easier for users to tweak it to their liking..
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

rych
Warlord
Warlord
Posts: 766
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

dump-session: too many error messages

Post#50 by rych » 29 Jul 2024, 09:16

ncmprhnsbl wrote:
21 Jul 2024, 02:12
making it easier for users to tweak it to their liking
rych wrote:
17 Jul 2024, 12:17
sleep 3 to the beginning of rc.6 (it may need longer
Having done all these tweaks, and same others perhaps (e.g. excluding /var path in its entirety from changes-exit.conf so it's never saved in /changes) to minimize saved changes... a curious thing happens. My bash history is no longer saved: not only between different instances of "sakura" terminal, as I think used to be the case, but now also after reboot: the command line history of last session isn't here. Basically, the new history is never committed, unless I explicitly issue `history -w`... or close the current terminal properly. Perhaps, that sleep 3 to the beginning of rc.6 is in deed needed for things like this... I'll keep investigating.

UPDATE. Interesting! Sakura only commits its CLI command history to the .bash_history file after it closes. Now what if in this instance of Sakura we 1) changes-commit, 2) clear the changes-exit flag by e.g.,

Code: Select all

mv -f /mnt/live/tmp/changes-exit /mnt/live/tmp/changes-exitDONE
and 3) issue poweroff? Even if Sakura has enough time to exit, and commit history to .bash_history, it is not saved to changes anymore -- we're proceeding to a speedy shutdown! Maybe I should let the changes-commit happen once again at the very end inside rc.6 just to catch any last second changes the system writes down to its proper locations?!

User avatar
Ed_P
Contributor
Contributor
Posts: 8908
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

dump-session: too many error messages

Post#51 by Ed_P » 29 Jul 2024, 22:32

You could try closing Sakura, running your backup script which could backup your /home/guest/.bash_history file then run your shutdown script. Or maybe adding the backup of the /home/guest/.bash_history file to your shutdown script. But then a script to restore it would be needed. :hmmm:

rych
Warlord
Warlord
Posts: 766
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

dump-session: too many error messages

Post#52 by rych » 05 Aug 2024, 11:45

rych wrote:
29 Jul 2024, 09:16
changes-commit happen once
I've decided that committing changes should better happen at the system shutdown after all the apps have exited and flushed their states into changes. Sakura is only one example of such an app, many others while open won't be updating their storage, and the only way we have them all flushed is if we close them.

My syncing script ( synchronizing my frugal and USB installation or Porteus to be identical) that calls changes_commit now postpones changes synchronization:

Code: Select all

echo "Postponing changes sync until after changes-commit at system shutdown in rc.6"
echo "$PORTDIR/changes/ $Dest/$PortFolder/changes/" > /mnt/live/tmp/changes-syncFromTo
Then in rc.6 I've added:

Code: Select all

[ -f /mnt/live/tmp/changes-syncFromTo ] && changes-sync
changes-sync is a new script that simply does this essentially:

Code: Select all

rsync -a --delete --stats $(cat /mnt/live/tmp/changes-syncFromTo) | grep "Number of"
So, when we've committed the changes at the shutdown, it's also the right, final occasion to sync it to another folder if needed (or to make a changes<date>.xzm for example).

User avatar
Ed_P
Contributor
Contributor
Posts: 8908
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

dump-session: too many error messages

Post#53 by Ed_P » 05 Aug 2024, 19:11

rych wrote:
05 Aug 2024, 11:45
So, when we've committed the changes at the shutdown, it's also the right, final occasion to sync it to another folder if needed
But won't this jink your 2 second shutdown ? :)
rych wrote:
16 Jul 2024, 14:29
In the rest 99.9% cases I just want a 2 seconds quick shutdown
And if the other folder is full??

Basically back to the current changes=EXIT and save.dat file situation. :happy62:

rych
Warlord
Warlord
Posts: 766
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

dump-session: too many error messages

Post#54 by rych » 06 Aug 2024, 13:09

Ed_P wrote:
05 Aug 2024, 19:11
And if the other folder is full?
The /changes folder is expected to be on a large enough partition and the user is advised to keep an eye on how big that folder grows. I keep my /changes small. So, it commits and syncs very fast. If the target folders were ever full then either cp or rsync would return an error rather than saving or synching the changes and the user would be noticing that the new changes aren't preserved. I don't see a problem even in that very unlikely event.
Ed_P wrote:
05 Aug 2024, 19:11

Basically back to the current changes=EXIT
No, again: the changes-commit script was fixed by ncmprhnsbl, unified, and taken out of initrd to rc.6 where people like me can customize it and follow it with an optional synchronization.

This thread can now be closed as [Solved].

User avatar
Ed_P
Contributor
Contributor
Posts: 8908
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

dump-session: too many error messages

Post#55 by Ed_P » 06 Aug 2024, 14:47

rych wrote:
06 Aug 2024, 13:09
The /changes folder is expected to be on a large enough partition and the user is advised to keep an eye on how big that folder grows.
I always use changes=EXIT for faster performance and normally use a save.dat file, currently 512MB, and in the past I've lost a lot of saved files: scripts, tweaks, bookmarks, screen prints, etc when I shutdown Porteus and the changes were bigger than the save.dat file. On USB drives I have a single partition for all Porteus folders and changes, the USB drives are old and small, 4GB - 8GB and formatted to FAT32, and I have lost data on them also when shutting down. So having the shutdown process check for space before writing to the drive, or file, and stopping if there isn't enough space is important for users who do stupid things without checking space usage effects. :)

rych
Warlord
Warlord
Posts: 766
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

dump-session: too many error messages

Post#56 by rych » 07 Aug 2024, 07:57

Ed_P wrote:
06 Aug 2024, 14:47
having the shutdown process check for space before writing to the drive
Yes, and that's another useful addition to the new, soon to be official changes-commit script. It's going to warn the user if the save.dat or /changes is getting full, so the next session they should do something about it. I've just customized it away for my case.

Post Reply