How I use git-annex

I use git-annex  for managing my movie collection and application installers. I often add new content from my laptop and I want to propagate it to my servers and then drop it locally. Doing this manually is tedious so I wrote a very simple bash script that does it for me. Maybe some of you would like to do something similar so I might just as well publish it here. It should be obvious that you have to tweak it to match your directory and server structure.

You may notice that I run “git add scripts” instead of “git annex add scripts” since this folder contain small files that I want to keep under version control.

Disclaimer: It’s not written in the most efficient way possible but works well for me. However please give comments if you think I’m doing something really silly.

Updated: New version with improved but not perfect error handling


#!/bin/sh

stores=(media elements media2 docsnmedia)

laptop=~/AnnexMedia

cd $laptop
git annex add Video
git annex add Computing
git add scripts
git commit -m "added new content"

# Pull from servers in case I added something there also
for item in ${stores[*]}
do
if [ -d /Volumes/$item/Media ]
then
echo "$item is connected"
cd $laptop
git fetch $item
git pull $item master
fi
done

# Pull the new (merged) tree from laptop and fetch all content to each server
for item in ${stores[*]}
do
if [ -d /Volumes/$item/Media ]
then
cd /Volumes/${item}/Media
echo "Fetching to $item"
git fetch laptop
git pull laptop master
git annex get
git commit -m "m"

cd $laptop
git pull $item
git pull $item master
fi
done

# Drop all movies on laptop
cd $laptop
git annex drop Video

About these ads
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s