Ideally, as a wish, KOReader would completely separate its "data" files from its "system" files, so even as things change, all you would have to do is backup one folder and it would (almost always) survive future updates (like the recent defaults.custom.lua change that I only found out about after restoring my old backup and losing my defaults settings). This would mean moving settings.reader.lua, defaults.custom.lua, styletweaks, custom fonts, history, screenshots, patches to the existing "settings" folder, so we can just back up that "settings" folder. The SDR files are fine where they are among the books imo.
My backup script as of today, mostly based on @NiLuJe's script above but updated for the latest KOReader. I run it when the Kindle/Kobo is connected over USB to a Mac. The LIBRARY_ROOT, KOREADER_DIR, and TMPFS_PATH lines are for Kindle right now, but the Kobo alternative is commented out, so you can switch to that version if you use Kobo. Or adapt these 3 paths to whatever computer OS and ereader you have.
Quote:
# Catch failures
set -e
set -o pipefail
# Root directory of the Library
LIBRARY_ROOT="/Volumes/Kindle/books"
#LIBRARY_ROOT="/Volumes/KOBOeReader/.books"
# KOReader install directory
KOREADER_DIR="/Volumes/Kindle/koreader"
#KOREADER_DIR="/Volumes/KOBOeReader/.adds/koreader"
# We'll work in a tmpfs
cd ~/Desktop
TMPFS_PATH="kindle-koreader-$(date +%F)"
#TMPFS_PATH="kobo-koreader-$(date +%F)"
mkdir -p "${TMPFS_PATH}"
cd "${TMPFS_PATH}"
# Start by collecting the list of sidecar directories we'll want to backup...
echo "* Computing sidecar folders list . . ."
find "${LIBRARY_ROOT}" -type d -name '*.sdr' -print0 > sidecar_list
echo
# Then we want to backup KOReader's settings
echo "* Computing KOReader settings list . . ."
KO_FILES="cache/calibre/libraries.lua cache/calibre/books.dat defaults.custom.lua history.lua settings.reader.lua"
KO_FOLDERS="clipboard history settings styletweaks patches screenshots fonts/custom"
# Allow skipping dictionaries...
if [ "$#" -ge 1 ] ; then
KO_DICT_FOLDERS=""
else
KO_DICT_FOLDERS="data/dict data/tessdata"
fi
for path in ${KO_FILES} ${KO_FOLDERS} ${KO_DICT_FOLDERS} ; do
echo -en "${KOREADER_DIR}/${path}\0" >> koreader_list
done
echo
# Compute the final list
cat sidecar_list koreader_list > input_file_list
# Tar it up...
BACKUP_FILE="${TMPFS_PATH}.tar.gz"
echo "* Creating tarball . . ."
bsdtar -cf "${BACKUP_FILE}" --zstd -T input_file_list --null --exclude '*.old' --exclude '*.old_dom*' --exclude '*.old.[0-9]' || true
echo
# Remove lists
rm -f sidecar_list koreader_list input_file_list
# Move tar to Desktop
mv "${BACKUP_FILE}" ~/Desktop/
# Remove temp folder
cd ~/Desktop
rm -rf "${TMPFS_PATH}"
# We're done! Don't actually unmount the tmpfs just yet... ;o)
echo "* Done, backup stored in ~/Desktop/${BACKUP_FILE}"
|