Sunday, July 2, 2006

Moving photos around behind f-spot's back

I've been using f-spot since it showed up in Ubuntu/Breezy and have been keeping all my photos in a directory structure like this:

/PHOTOS/Photos/2006.06.30/
/PHOTOS/Photos/2006.07.01/

But sometimes I've forgotten to unclick the "Copy file to the Photos folder" box in the photos import dialog and end up with photos under ~/Photos/. Recently I checked and found there were almost a gigabytes worth of photos under there.

So this is what I did to move them to under /PHOTOS/Photos/ and keep all the tags and metadata correct.


  • Back up /home and /PHOTOS to an external USB. I love rsnapshot.
    $ rsnapshot daily

  • make an extra backup of the f-spot database
    $ cp ~/.gnome2/f-spot/photos.db photos-backup.db

  • Start poking around the f-spot database and updating it.
    $ sqlite3 ~/.gnome2/f-spot/photos.db
    sqlite> .schema photos
    CREATE TABLE photos ( id INTEGER PRIMARY KEY NOT NULL,
    time INTEGER NOT NULL,
    directory_path STRING NOT NULL,
    name STRING NOT NULL,
    description TEXT NOT NULL,
    default_version_id INTEGER NOT NULL
    );


  • See how many photos are in ~/Photos...
    sqlite> select count(*) from photos where directory_path like '/home/marc/Photos/%';
    260


  • Take a look at a few of them to see the path names...
    sqlite> select directory_path from photos where directory_path like '/home/marc/Photos/%' limit 0,10;


  • Update the pathname to my prefered one. I've added an 'a' to the end just so I won't overwrite an existing directory.
    sqlite> update photos set directory_path = "/PHOTOS/Photos/2006.06.22a" where directory_path = "/home/marc/Photos/2006/6/22";
    sqlite> .quit


  • Make the directory and move the files to the new location...
    mkdir /PHOTOS/Photos/2006.06.22a
    mv -v /home/marc/Photos/2006/6/22/HPIM117* /PHOTOS/Photos/2006.06.22a


  • Repeat for each directory. I did it all within emacs' shell so cut-n-paste made it a snap.