Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 03-10-2014, 01:59 AM   #1
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
linux backup of Kindle, annotations/pagenumbers/stuff with rsync

Just thought I'd share a script I use to backup my Kindle ebooks with the sidecar data. But first:


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 (of the default type "Text, column shown in the tag browser") 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 Save 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,&)}'
	)
)
Copy this code into the Save Template field of the device driver (see post #3 for details).

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.



Now the script:

In order to preserve the .sdr/ and book data, I use an rsync script outside of calibre (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 might 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/"
# These go in the backup folder
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
backup-excludes file:
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/

#JAILBREAK#
- /acxe/
- /developer/
- /extensions/
- /linkss/
- /python/
- /usbnet/
restore-excludes file:
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/*

#JAILBREAK#
- /acxe/
- /developer/
- /extensions/
- /linkss/
- /python/
- /usbnet/
Attached is an archive of the actual scripts, which you can unpack to your user profile.
Attached Files
File Type: gz kindlesync.tar.gz (1.5 KB, 217 views)

Last edited by eschwartz; 03-08-2015 at 03:14 AM. Reason: update excludes and stuff
eschwartz is offline   Reply With Quote
Old 03-26-2014, 03:08 AM   #2
nynaevelan
eBook Junkie
nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.
 
nynaevelan's Avatar
 
Posts: 1,526
Karma: 1464018
Join Date: May 2010
Location: USA
Device: Kindle Fire 2020, Kindle PW2
Quote:
Originally Posted by eschwartz View Post
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:

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.

Eschwartz: I am confused, where am I adding this template to use to send to my kindle for the original file name??
nynaevelan is offline   Reply With Quote
Advert
Old 03-26-2014, 03:07 PM   #3
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
The device-specific driver. When a Kindle is plugged in, it's in the dropdown under "Device".

Or you can go to Preferences ==> Advanced ==> Plugins ==> Search for plugin (text input box) and search for "kindle".

See screenshots.
Attached Thumbnails
Click image for larger version

Name:	calibre-configure-device.png
Views:	579
Size:	29.3 KB
ID:	120843   Click image for larger version

Name:	calibre-plugins-kindle2.png
Views:	573
Size:	177.0 KB
ID:	120844  
eschwartz is offline   Reply With Quote
Old 03-26-2014, 05:32 PM   #4
nynaevelan
eBook Junkie
nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.
 
nynaevelan's Avatar
 
Posts: 1,526
Karma: 1464018
Join Date: May 2010
Location: USA
Device: Kindle Fire 2020, Kindle PW2
Is there a way to tell it to send to a folder in the documents folder that is the same as the tags field??
nynaevelan is offline   Reply With Quote
Old 03-26-2014, 07:23 PM   #5
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Yes, you can put whatever you want into

Code:
template(
	'{your} - {template}/{here}'
)
as the template to use when "#file" is empty.
eschwartz is offline   Reply With Quote
Advert
Old 03-26-2014, 09:41 PM   #6
nynaevelan
eBook Junkie
nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.
 
nynaevelan's Avatar
 
Posts: 1,526
Karma: 1464018
Join Date: May 2010
Location: USA
Device: Kindle Fire 2020, Kindle PW2
Quote:
Originally Posted by eschwartz View Post
Yes, you can put whatever you want into

Code:
template(
	'{your} - {template}/{here}'
)
as the template to use when "#file" is empty.
No, not when it is empty, I want it to put in like \{tags}\template program so that it is in the separate folder with the file named from your program.
nynaevelan is offline   Reply With Quote
Old 03-27-2014, 02:46 PM   #7
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
The whole point is to prevent that from happening. It should always overwrite the previous location, to match up to the .sdr folder even after metadata is changed. Otherwise, I'd just stick the books in at the default location.

Wherever the books are, Amazon should still sync annotations to it, when next connected to WiFi. I am striving for semi-independence from Amazon's servers here.
eschwartz is offline   Reply With Quote
Old 03-29-2014, 05:45 PM   #8
nynaevelan
eBook Junkie
nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.
 
nynaevelan's Avatar
 
Posts: 1,526
Karma: 1464018
Join Date: May 2010
Location: USA
Device: Kindle Fire 2020, Kindle PW2
Quote:
Originally Posted by eschwartz View Post
The whole point is to prevent that from happening. It should always overwrite the previous location, to match up to the .sdr folder even after metadata is changed. Otherwise, I'd just stick the books in at the default location.

Wherever the books are, Amazon should still sync annotations to it, when next connected to WiFi. I am striving for semi-independence from Amazon's servers here.
Ok that makes sense, thanks.
nynaevelan is offline   Reply With Quote
Old 04-08-2017, 12:24 AM   #9
henriquemaia
Ignorant of many things
henriquemaia can eat soup with a fork.henriquemaia can eat soup with a fork.henriquemaia can eat soup with a fork.henriquemaia can eat soup with a fork.henriquemaia can eat soup with a fork.henriquemaia can eat soup with a fork.henriquemaia can eat soup with a fork.henriquemaia can eat soup with a fork.henriquemaia can eat soup with a fork.henriquemaia can eat soup with a fork.henriquemaia can eat soup with a fork.
 
henriquemaia's Avatar
 
Posts: 63
Karma: 9304
Join Date: Feb 2011
Device: Kobo Libra 2
Thumbs up

Sorry for necrobumping, but I wanted to thank you for this script. I was wondering if there was a way to backup the sdr files and folders, and found this thread through the search engine.

Thank you for providing such elegant solution. It makes our kindle usage even more reliable.

henriquemaia is offline   Reply With Quote
Reply

Tags
kindle backup, rsync, sdr


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
fetching annotations with Apple stuff tsolignani Library Management 3 03-28-2013 02:52 PM
How can I export or backup highlights and annotations under Adobe Digital Editions 2? oblador Reading and Management 0 03-20-2013 03:24 PM
Rsync on Kindle Touch leonardo84 Kindle Developer's Corner 11 10-31-2012 05:31 PM
How to easily backup all your notes, marks & reading positions with rsync under Linux Dylan Tomorrow Amazon Kindle 5 10-26-2012 03:18 PM
Linux friendly reader with annotations? picco Which one should I buy? 2 07-26-2012 09:35 AM


All times are GMT -4. The time now is 08:32 AM.


MobileRead.com is a privately owned, operated and funded community.