08-11-2014, 01:23 PM | #1 |
Handy Elephant
Posts: 1,736
Karma: 26785668
Join Date: Dec 2009
Location: Southern Sweden, far out in the quiet woods
Device: Thinkpad E595, Ubuntu Mate, Huawei Mediapad 5, Bouye Likebook Plus
|
Linux: Automatic rsync snapshot of the calibre libraries
I suspect there are many that use rsync in weird and wonderful ways to backup their calibre libraries.
There are two reasons why it is nice to use rsync to make snapshots. The first reason is that it syncs. So only modified files have to be copied. This means that it is very fast and efficient. The second reason is that rsync can create hard links to unchanged files, so each snapshot still looks like a full backup, but unchanged files are only copied once. This means that you can have a very large amount of snapshots, and they don't take up much more space than they really need. No need to store duplicate files. Each file only has to be copied if it changes. The hard links are to previous copies in the snapshots. And these hard linked files use a copy counter, so you can freely delete snapshots. Only when you delete the last copy is that file really deleted. Here is how I do it. (Ubuntu 14.04.01) ~/bin/snapshot_calibre.sh This executable script is a general "snapshotter" that I have written and configured to make snapshots of my calibre libraries. It has to be edited to specify where the calibre libraries are and where the snapshots are to be stored, and for how many days you want to keep snapshots. This script can easily be copied and changed to make snapshots of other folders as well. I also use it to make snapshots of my documents folder. It is then set up to make a new snapshot every time I start the computer. It is best if you have the snapshot on an other drive, or even on another computer. I have all my snapshots on my NAS. If you need to use a snapshot to restore lost data, copy the entire snapshot before you start changing or editing anything. Otherwise you may mess up other snapshots. ~/bin/calibre This is also a script that is executable. All it does is launch /opt/calibre/calibre and then when calibre is exited, it immediately runs ~/bin/snapshot_calibre.sh. The nice thing about this is that commands in ~/bin takes precedence over other commands. So there is no need to change anything else to automate the snapshots. The normal launcher in Unity will use this script and updates of calibre will not overwrite anything. I haven't tested this trick in other environments... One cause of problem may be if you start and exit calibre quickly several times, before snapshot_calibre.sh has had time to sync. Especially the first time you sync, when the sync can take a while. Just don't do it. ~/bin/snapshot_calibre.sh Spoiler:
~/bin/calibre Spoiler:
How do you use rsync? Last edited by Adoby; 08-11-2014 at 01:56 PM. |
08-11-2014, 02:19 PM | #2 |
Ex-Helpdesk Junkie
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)
|
I'd do much the same... (but I don't feel the need for backups, ATM. I do use rsync to dropbox the libraries, though.)
Why don't you explicitly kill the snapshot process or do some sort of check with a lockfile, before launching /opt/calibre/calibre Last edited by eschwartz; 08-11-2014 at 02:21 PM. |
Advert | |
|
08-11-2014, 02:36 PM | #3 |
Handy Elephant
Posts: 1,736
Karma: 26785668
Join Date: Dec 2009
Location: Southern Sweden, far out in the quiet woods
Device: Thinkpad E595, Ubuntu Mate, Huawei Mediapad 5, Bouye Likebook Plus
|
I've never had any problem with this. So I never bothered to add any lockfile or similar. Usually a sync is done in seconds. And even if I relaunch calibre quickly, the sync can continue while calibre is launched and while I use it. I just thought I should mention it as a potential problem.
|
08-11-2014, 03:25 PM | #4 | |
Ex-Helpdesk Junkie
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)
|
Quote:
*mentions it as a problem but doesn't even care enough to bother himself, hmph. muttermuttermutter...* |
|
08-13-2014, 05:24 AM | #5 |
Handy Elephant
Posts: 1,736
Karma: 26785668
Join Date: Dec 2009
Location: Southern Sweden, far out in the quiet woods
Device: Thinkpad E595, Ubuntu Mate, Huawei Mediapad 5, Bouye Likebook Plus
|
OK!
I accepted the implied challenge and improved the script. Now I use flock to ensure that only one instance of the script can run, use zenity to provide some feedback while the snapshot is written by rsync and write a small log to each snapshot folder. Also it is now all in one file, this is no longer a general folder snapshotter that is used to take snapshots of the calibre libraries. It is now a calibre launcher script that also takes a snapshot after calibre exits. Both flock and zenity are installed by default in Ubuntu 14.04.01, and also in many other dists, I think. So typically no need to do anything other than fill in the correct paths, place the script in the file ~/bin/calibre and make it executable. ~/bin/calibre Spoiler:
|
Advert | |
|
Tags |
automated, backup, linux, rsync, snapshots |
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Fully automatic calibre installer/updater for linux | eschwartz | Related Tools | 43 | 02-08-2022 06:59 PM |
linux backup of Kindle, annotations/pagenumbers/stuff with rsync | eschwartz | Kindle Developer's Corner | 8 | 04-08-2017 12:24 AM |
Does Calibre Keep a Snapshot of Device Contents? | Jimbo724 | Devices | 3 | 09-12-2013 09:29 AM |
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 |
Missing libraries in calibre binary release for Linux | davide125 | Calibre | 5 | 09-02-2011 07:53 AM |