Background 

I use TiddlyWiki from NodeJs. Here is the official documentation 
<https://tiddlywiki.com/#Installing%20TiddlyWiki%20on%20Node.js> on it. To 
make offline copy, use the command

tiddlywiki mynewwiki --build index

It generates a file index.html in the output folder. When the command is 
run again, the index.html is overwritten. I was interested in keeping the 
backups intact, like so

index-2018-06-20-1131.html
index-2018-06-30-0040.html
index-2018-07-05-0037.html
index-2018-07-05-1839.html
index-2018-07-06-0154.html

This way, I can have a timeline of my TiddlyWiki backups, enabling me to 
restore any particular backup.
Solution 

I wrote following shell script. 

   1. It saves TiddlyWiki to file using build command 
   2. Appends timestamp to the filename 

function tiddlysave
    set p /Users/talha/Dropbox/TiddlyNotes/output/
    set f index.html

    set file "$p""$f"
    tiddlywiki ~/Dropbox/TiddlyNotes --verbose --build index

    if test -e "$file"
        set_color -o red
        echo "index.html found"

        set append (stat -f "%Sm" -t "%F-%H%M" "$file")
        set rootname (echo $f | sed 's/\.[^.]*$//')
        set ext (echo $file | sed 's/.*\.//')
        set new "$p""$rootname"-"$append"."$ext"

        set_color -o yellow
        echo "Rename $file → $new"
        set_color normal

        mv -v "$file" "$new"
    endend

Now all I have to do, is to run tiddlysave command from any folder in the 
system. I tend to run this command after making any significant change in 
TiddlyWiki or trying any new plugin or macro.

I can also setup a cron job to take backups at regular intervals.
Limitations 

It runs on Fish Shell <http://fishshell.com/> and macOS.

Modifying it for bash shouldn’t be difficult at all. Though on Linux, stat 
command works differently. Instead of stat -f "%Sm" -t "%F-%H%M" $file you 
can use

stat -c %y filename 
# or
date -r filename

Why not rely on Dropbox Version support? 

Dropbox automatically creates version of files. But with tiddlysave, I am 
in control when to take backup.

Hope someone will find it helpful.
​

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/b7b03f92-1538-4292-aba0-e2383ff3a704%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to