I'd like to show you an alternative way of saving files with dump-session as using the changes=EXIT: cheatcode. The idea is to copy files straightforward from aufs to your persistent mount -- avoiding the need of a temporary folder. This saves writes and memory and feels faster. Besides you can now use spaces in your `changes-exit.conf' and there some are other minor tweaks. Wildcards can also be used as before. I'm using it at present and it seems to work ok.
Please note
- You can add lines like these to your changes-exit.conf file
/home
!/home/guest/.cache/moonchild productions
!/home/guest/.serverauth.* - WDIR is not present. No need to copy files to a temporary folder.
- find outputs files from wanted folders and grep -Ev excludes unwanted.
- cp -uaf just updates files -- it doesn't make a bulk copy
- If you create a folder without any file inside it will not be saved. New folders with at least one file will be saved.
Thank you!
Code: Select all
#!/bin/bash
# /opt/porteus-scripts/dump-session
# Save live session ...
# Script takes action only when 'changes=EXIT' cheatcode is used.
# Author: fanthom <fanthom@porteus.org>
# Modification proposed by: abelM - forum.porteus.org
# 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"
# Configuration file
FOLDERS_CONF="/etc/changes-exit.conf"
# Save: build expresion for `find'
FOLDERS="$(grep '^/' $FOLDERS_CONF | sed 's/.//')"
# Exclude: build expresion for `grep -Ev'
XFOLDERS="$(grep '^!/' $FOLDERS_CONF | sed -e 's/../^/' \
-e 's/\./\\./g' -e 's/\?/./g' -e 's/\*/.*/g' \
| tr '\n' '|' | sed -e 's/|$//')"
# List of files to copy
FILES_CP="/tmp/files_cp.lst"
## 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: set IFS to EOL
IFS="
"
# Handle whiteouts properly:
for x in $(find $FOLDERS -name ".wh.*" | sed 's/\.wh\./g/'); do test -e "$MNAME/$x" && rm -rf "$MNAME/$x"; done
for y in $(find $MNAME -name ".wh.*"); do wh="$(echo $y | sed -e 's^$MNAME^^g' -e 's/\.wh\./g/')"; test -e "$wh" && rm "$y"; done
# Merge changes with 'changes=EXIT' destination:
# BUILD LIST OF FILES SKIPPING EXCLUDED FOLDERS
if test -n "$XFOLDERS"; then
find $FOLDERS -not -type d | grep -Ev "$XFOLDERS" > "$FILES_CP"
else
find $FOLDERS -not -type d > "$FILES_CP"
fi
# UPDATE FILES NOW
cp -uaf --parents `cat "$FILES_CP"` "$MNAME"
# Reset IFS to default
unset IFS
# Remount aufs with 'udba=none' flag:
mount -o remount,udba=none /
echo "session saved"