Just thought I'd share a script I use to backup my Kindle sidecar data.
I use a custom column in calibre to make Amazon-sourced books match up to the .sdr data, so I can keep my notes/annotations even for sideloaded books and don't have to worry about syncing to Amazon etc.
The custom column is named "#file", titled "Original Filename". In it, I store the filename that the Amazon book had when I added it from my Kindle, minus the file extension. It will be in the form of {book-title}_{ASIN}.
I use a custom template for sending to device, (limited to the kindle2 device driver, since other devices don't need this,) which looks like this:
It uses the contents of custom column "file" as the savepath, if available. If not, (for instance, it isn't originally from Amazon, so I left it blank) it falls back on the main template, which I actually tweaked to only use the first author.
To preserve the .sdr data, I use an rsync script (saved as "$HOME/bin/kindlesync") which saves the contents of "/media/Kindle" not including the tts or index files and stuff, just the parts that mght ever need to be preserved.
This also lets me restore my Kindle if it ever needs to be reset to factory conditions, or if I get a new device. :)
kindlesync script:
backup-excludes file:
restore-excludes file:
I use a custom column in calibre to make Amazon-sourced books match up to the .sdr data, so I can keep my notes/annotations even for sideloaded books and don't have to worry about syncing to Amazon etc.
The custom column is named "#file", titled "Original Filename". In it, I store the filename that the Amazon book had when I added it from my Kindle, minus the file extension. It will be in the form of {book-title}_{ASIN}.
I use a custom template for sending to device, (limited to the kindle2 device driver, since other devices don't need this,) which looks like this:
Code:
program:
ifempty(
field('#file'),
template(
'{author_sort:sublist(0,1,&)}/{title} - {authors:sublist(0,1,&)}'
)
)
It uses the contents of custom column "file" as the savepath, if available. If not, (for instance, it isn't originally from Amazon, so I left it blank) it falls back on the main template, which I actually tweaked to only use the first author.
To preserve the .sdr data, I use an rsync script (saved as "$HOME/bin/kindlesync") which saves the contents of "/media/Kindle" not including the tts or index files and stuff, just the parts that mght ever need to be preserved.
This also lets me restore my Kindle if it ever needs to be reset to factory conditions, or if I get a new device. :)
kindlesync script:
Code:
#!/bin/bash
## Set defaults
backup_folder="$HOME/Kindle Stuff/Kindle Backups/"
backup_excludes=.rsync-backup-exclude
restore_excludes=.rsync-restore-exclude
##### Declare usage
usage()
{
cat <<- _EOF_
Usage: kindlesync [OPTIONS]
Back up contents of Kindle drive as Kindle.rsync
Does not include system info or TTS
Deletes:
Personal Letters
EndActions
.fuse and .goutputstream garbage
OPTIONS
--backup-excludes
optional excludes file for backup
defaults to: '$backup_excludes'
--restore-excludes
optional excludes file for restore
defaults to: '$restore_excludes'
-f, --folder chooses backup folder, defaults to:
'$backup_folder'
-b, --backup perform backup only
-r, --restore perform restore only
-d, --dry-run backup, then do restore in test mode
-h, --help show this usage message then exit
_EOF_
}
##### Test for interactive options
## By default, all switches turned off
backup_only=
restore_only=
dry_restore=
while [ "$1" != "" ]; do
case $1 in
-h|--help) usage
exit
;;
-f|--folder) shift
backup_folder=$1
;;
--backup-excludes) shift
backup_excludes=$1
;;
--restore-excludes) shift
restore_excludes=$1
;;
-b|--backup) backup_only=1
;;
-r|--restore) restore_only=1
;;
-d|--dry-run) dry_restore=1
;;
*) echo "kindlesync: unrecognized option '$1'"
echo "Try 'kindlesync --help' for more information."
exit 1
esac
shift
done
##### Declare Functions
do_backup()
{
rsync -amv --exclude-from=$backup_excludes /media/Kindle/ ./Kindle.rsync
}
do_restore()
{
rsync -amv --exclude-from=$restore_excludes --delete ./Kindle.rsync/ /media/Kindle
}
do_dry_restore()
{
rsync -amv --dry-run --exclude-from=$restore_excludes --delete ./Kindle.rsync/ /media/Kindle
}
################################################################################################
##### OLD SYNC ONLY DOCUMENTS FOLDER ###########
##### ###########
##### rsync -amv --exclude-from=.rsync-exclude /media/Kindle/documents/ ./documents ###########
##### rsync -amv --delete ./documents/ /media/Kindle/documents ###########
################################################################################################
#### MAIN
if [ ! -d /media/Kindle/ ]; then
echo "Your Kindle is not plugged in."
exit 1
fi
cd "$backup_folder"
if [ "$backup_only" = "1" ]; then
echo "Backing up to: $(pwd)/Kindle.rsync"
do_backup
elif [ "$restore_only" = "1" ]; then
echo "Restoring..."
do_restore
elif [ "$dry_restore" = "1" ]; then
echo -e "Backing up to: $(pwd)/Kindle.rsync\n\n"
do_backup
echo -e "Simulating restore; this isn't really happening.\n\n"
do_dry_restore
else
echo -e "Backing up to: $(pwd)/Kindle.rsync\n\n"
do_backup
echo -e "Restoring...\n\n"
do_restore
fi
Code:
#DOCUMENTS JUNK#
###Stupid letters I never read
- Personal\ letter*
- .fuse*
- .goutputstream-*
###I hate EndActions
- EndActions*
###Don't delete, since it may tell Amazon to download more .sdr
###But I don't need it in the backup
- *.partial
#SYSTEM#
+ /system/
+ /system/thumbnails/
+ /system/thumbnails/*
- /system/*
#TTS#
- /tts/
#Sandbox#
- /.active_content_sandbox/
Code:
- /tts/
- /.active_content_sandbox/
###Don't delete, since it may tell Amazon to download more .sdr
- /documents/*.partial
#SYSTEM#
+ /system/
+ /system/thumbnails/
+ /system/thumbnails/*
- /system/*