Posted: 2016-01-05 23:43:55 by Alasdair Keyes
I've been at my new job for 3 months now and my home folder is slowly growing in size. Like most people often have files that are updated frequently, spreadsheets, build specs etc and I thought it would be quite nice to have a quick and dirty versioning system for my documents.
I didn't want to get too in-depth with log structured filesystems such as NILFS or really have to use a new FS or fuse-based FS as it seems an unnecessary length to go to. I don't have any requirement to store every single version, but just give me snapshots I could refer back to in future or easily restore mistakenly deleted files.
I decided that git would be a suitable base for this for the following reasons
I started by initializing my docs
$ cd /home/akeyes/mydocs
$ git init
Initialised empty Git repository in /home/akeyes/mydocs/.git
$ git add .
$ git commit -m "Initial commit"
[master (root-commit) 4cbb3d8] Initial commit
152 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 xxxxxx.docx
create mode 100644 xxxxxx.odt
...
create mode 100644 xxxxxx.txt
Now I have my initial commit, I wrote the followig script to add to cron
#!/bin/bash
FOLDER=/home/akeyes/mydocs
cd $FOLDER
if [ `git status --porcelain | wc -l` -gt 0 ]; then
git add --all .
git commit -m "Checkpoint"
fi
I was unaware of the --porcelain
argument for git, but it essentially shows a simple machine parseable output of git status. For my usage if there's any output, it shows there's a change and it needs to be snapshotted
$ git status --porcelain
?? newfile
?? newfile1
the --all
switch to git add allows git add to succesfully add in file deletions and not require git rm
To start with I just added this into my crontab
* * * * * /home/akeyes/checkpoint_docs.sh
And now git log
shows my versioning working
$ git log --name-only
commit d0544e40b856eb98cc2129f98383895708083deb
Author: Alasdair Keyes <x@x.com>
Date: Tue Jan 5 19:47:00 2016 +0000
Checkpoint
newfile2
commit 139fd9ff825232e0551bf570e4ac8957bc93c8b1
Author: Alasdair Keyes <x@x.com>
Date: Tue Jan 5 19:46:00 2016 +0000
Checkpoint
newfile
newfile2
newfile3
commit 8539658cd62581c3a514081c30d3c30a2a0a7ac9
Author: Alasdair Keyes <x@x.com>
Date: Tue Jan 5 19:45:00 2016 +0000
Checkpoint
newfile
newfile1
commit ba6ec4f43aecb81db0709ea18418d94d24cbb3d8
Author: Alasdair Keyes <x@x.com>
Date: Tue Jan 5 19:42:33 2016 +0000
Initial commit
xxxxxx.docx
xxxxxx.odt
xxxxxx.txt
It seems to work very well, on top of this I've created a .gitignore
# Libreoffice temp files
**/.~*#
# VIM swap files
**/.*.swp
# Keepass lock files
**/*.lock
Which stops temp files from LibreOffice being commited.
If you found this useful, please feel free to donate via bitcoin to 1NT2ErDzLDBPB8CDLk6j1qUdT6FmxkMmNz
© Alasdair Keyes
I'm now available for IT consultancy and software development services - Cloudee LTD.
Happy user of Digital Ocean (Affiliate link)